]> saetta.ns0.it Git - zakform/json/commitdiff
Converted ZakFormElementArray in Json array.
authorAndrea Zagli <azagli@libero.it>
Mon, 10 Aug 2020 14:36:33 +0000 (16:36 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 10 Aug 2020 14:36:33 +0000 (16:36 +0200)
src/form.c

index 19d80c8197f3bb3bfb8a1bbdc1475e5bcde6420e..4220adff1c833e9ced34ea712ad9de2e82534dba 100644 (file)
@@ -446,12 +446,46 @@ zak_form_json_provider_insert (ZakFormIProvider *provider, GPtrArray *elements)
                                {
                                        JsonNode *jnode;
 
-                                       value = zak_form_element_unformat_gvalue (element, zak_form_element_get_value_gvalue (element));
+                                       if (ZAK_FORM_IS_ELEMENT_ARRAY (element))
+                                               {
+                                                       guint l;
+                                                       GPtrArray *ar_ar;
 
-                                       jnode = json_node_new (JSON_NODE_VALUE);
-                                       json_object_set_member (obj, zak_form_element_get_name (element), json_node_init_string (jnode, g_value_get_string (value)));
+                                                       JsonNode *jnode_ar;
 
-                                       g_value_unset (value);
+                                                       jnode_ar = zak_utils_json_node_new_array ();
+
+                                                       ar_ar = zak_form_element_array_get_elements (element);
+                                                       for (l = 0; l < ar_ar->len; l++)
+                                                               {
+                                                                       JsonNode *obj_ar;
+                                                                       JsonNode *obj_node_ar;
+
+                                                                       ZakFormElement *ar_element = (ZakFormElement *)g_ptr_array_index (ar_ar, l);
+
+                                                                       obj_ar = zak_utils_json_node_new_object ();
+                                                                       json_array_add_element (json_node_get_array (jnode_ar), obj_ar);
+
+                                                                       value = zak_form_element_unformat_gvalue (element, zak_form_element_get_value_gvalue (ar_element));
+
+                                                                       obj_node_ar = json_node_new (JSON_NODE_VALUE);
+                                                                       json_object_set_member (json_node_get_object (obj_ar), zak_form_element_get_name (ar_element), json_node_init_string (obj_node_ar, g_value_get_string (value)));
+
+                                                                       g_value_unset (value);
+                                                               }
+
+                                                       jnode = json_node_new (JSON_NODE_ARRAY);
+                                                       json_object_set_member (obj, zak_form_element_get_name (element), json_node_init_array (jnode, json_node_get_array (jnode_ar)));
+                                               }
+                                       else
+                                               {
+                                                       value = zak_form_element_unformat_gvalue (element, zak_form_element_get_value_gvalue (element));
+
+                                                       jnode = json_node_new (JSON_NODE_VALUE);
+                                                       json_object_set_member (obj, zak_form_element_get_name (element), json_node_init_string (jnode, g_value_get_string (value)));
+
+                                                       g_value_unset (value);
+                                               }
                                }
                }