typedef struct
{
gchar *filename;
+
+ JsonNode *root;
} ZakFormJsonProviderPrivate;
struct _ZakFormJsonProvider
ZakFormJsonProvider
*zak_form_json_provider_new_from_file (const gchar *filename)
{
- GKeyFile *kfile;
+ JsonParser *parser;;
GFile *gf;
GFileOutputStream *ostr;
GError *error;
ZakFormJsonProvider *zak_form_json_provider;
+ ZakFormJsonProviderPrivate *priv;
g_return_val_if_fail (filename != NULL && g_strcmp0 (filename, "") != 0, NULL);
g_object_unref (gf);
}
- kfile = g_key_file_new ();
+ parser = json_parser_new ();
error = NULL;
- if (!g_key_file_load_from_file (kfile, filename, G_KEY_FILE_NONE, &error))
+ if (!json_parser_load_from_file (parser, filename, &error))
{
- g_warning ("Unable to open ini file: «%s»\n. %s",
+ g_warning ("Unable to open json file: «%s»\n. %s",
filename,
error != NULL && error->message != NULL ? error->message : "No details.");
return NULL;
}
- zak_form_json_provider = zak_form_json_provider_new_from_gkeyfile (kfile, filename);
+
+ zak_form_json_provider = ZAK_FORM_JSON_PROVIDER (g_object_new (zak_form_json_provider_get_type (), NULL));
+ priv = zak_form_json_provider_get_instance_private (zak_form_json_provider);
+
+ priv->root = json_parser_get_root (parser);
+
+ return zak_form_json_provider;
+}
+
+/**
+ * zak_form_json_provider_new_from_data:
+ * @data:
+ * @length:
+ *
+ * Returns: the newly created #ZakFormJsonProvider object.
+ */
+ZakFormJsonProvider
+*zak_form_json_provider_new_from_data (const gchar *data, gssize length)
+{
+ JsonParser *parser;;
+
+ GError *error;
+
+ ZakFormJsonProvider *zak_form_json_provider;
+ ZakFormJsonProviderPrivate *priv;
+
+ g_return_val_if_fail (data != NULL && g_strcmp0 (data, "") != 0, NULL);
+
+ parser = json_parser_new ();
+
+ error = NULL;
+ if (!json_parser_load_from_data (parser, data, size, &error))
+ {
+ g_warning ("Unable to read data\n. %s",
+ error != NULL && error->message != NULL ? error->message : "No details.");
+ return NULL;
+ }
+
+ zak_form_json_provider = ZAK_FORM_JSON_PROVIDER (g_object_new (zak_form_json_provider_get_type (), NULL));
+ priv = zak_form_json_provider_get_instance_private (zak_form_json_provider);
+
+ priv->root = json_parser_get_root (parser);
return zak_form_json_provider;
}