]> saetta.ns0.it Git - zakform/json/commitdiff
Implemented ::load.
authorAndrea Zagli <azagli@libero.it>
Sun, 16 Aug 2020 15:56:12 +0000 (17:56 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 16 Aug 2020 15:56:12 +0000 (17:56 +0200)
src/form.c

index 278611c359d053daa2410e11fe458dbdfab773c0..ddd5b48e4660fa29ae5540e54b584c995c5a4bfa 100644 (file)
@@ -441,7 +441,45 @@ zak_form_json_provider_load (ZakFormIProvider *provider, GPtrArray *elements)
                        ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i);
                        if (zak_form_element_get_to_load (element))
                                {
-                                       zak_form_element_set_value (element, json_object_get_string_member (obj, zak_form_element_get_name (element)));
+                                       JsonNode *jnode;
+
+                                       jnode = json_object_get_member (obj, zak_form_element_get_name (element));
+                                       if (ZAK_FORM_IS_ELEMENT_ARRAY (element)
+                                           && json_node_get_node_type (jnode) == JSON_NODE_ARRAY)
+                                               {
+                                                       guint l;
+                                                       guint j;
+                                                       JsonArray *ar;
+
+                                                       GString *str;
+
+                                                       str = g_string_new ("");
+
+                                                       ar = json_node_get_array (jnode);
+                                                       l = json_array_get_length (ar);
+                                                       for (j = 0; j < l; j++)
+                                                               {
+                                                                       JsonObject *ar_obj;
+                                                                       GList *lst_membs;
+
+                                                                       ar_obj = json_array_get_object_element (ar, j);
+                                                                       lst_membs = json_object_get_members (ar_obj);
+
+                                                                       g_string_append_printf (str,
+                                                                                               "%s{\"%s\",\"%s\"}",
+                                                                                               str->len > 1 ? "," : "",
+                                                                                               (gchar *)lst_membs->data,
+                                                                                               json_object_get_string_member (ar_obj, (const gchar *)lst_membs->data));
+                                                               }
+
+                                                       zak_form_element_set_value (element, str->str);
+
+                                                       g_string_free (str, TRUE);
+                                               }
+                                       else
+                                               {
+                                                       zak_form_element_set_value (element, json_object_get_string_member (obj, zak_form_element_get_name (element)));
+                                               }
                                        zak_form_element_set_as_original_value (element);
                                }
                }