From 6d2f11e36364ea452d905f685845b2f0d8adbf58 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 10 Aug 2020 16:36:33 +0200 Subject: [PATCH] Converted ZakFormElementArray in Json array. --- src/form.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/form.c b/src/form.c index 19d80c8..4220adf 100644 --- a/src/form.c +++ b/src/form.c @@ -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); + } } } -- 2.49.0