Hello
I try to parse json but I've a problem with multiple object :
---
#include <zephyr/data/json.h>
---
struct elt{const char *a;const char *c[16]; // pointeur vers un tableau de chaînes de caractèressize_t num_c; // nombre d'éléments dans le tableau c};struct obj_array{struct elt elements[10];size_t num_elements;};static const struct json_obj_descr elt_descr[] = {JSON_OBJ_DESCR_PRIM(struct elt, a, JSON_TOK_STRING),JSON_OBJ_DESCR_ARRAY(struct elt, c, 16, num_c, JSON_TOK_STRING),};static const struct json_obj_descr obj_array_descr[] = {JSON_OBJ_DESCR_OBJ_ARRAY(struct obj_array, elements, 10, num_elements,elt_descr, ARRAY_SIZE(elt_descr)),};void main(void){int ret;struct obj_array obj_array_array_ts;printk("parse : \n");char encoded[] = "[{\"a\":\"ok\",\"c\":[\"text1\",\"text2\",\"text3\"]}]";printk("%s\n", encoded);k_sleep(K_MSEC(1000));ret = json_arr_parse(encoded, sizeof(encoded),obj_array_descr,&obj_array_array_ts);printk("r : %d\n", ret);if (ret){printk("error parsing");}else{for (size_t i = 0; i < obj_array_array_ts.num_elements; i++){printk("a: %s\n", obj_array_array_ts.elements[i].a);for (size_t j = 0; j < obj_array_array_ts.elements[i].num_c; j++){printk("c %d: %s\n", j, obj_array_array_ts.elements[i].c[j]);}}}}
With char encoded[] = "[{\"a\":\"ok\",\"c\":[\"text1\",\"text2\",\"text3\"]}]";
This is ok :
parse :
[{"a":"ok","c":["text1","text2","text3"]}]
r : 0
a: ok
c 0: text1
c 1: text2
c 2: text3
With char encoded[] = "[{\"a\":\"ok\",\"c\":[\"text1\",\"text2\",\"text3\"]},{\"a\":\"ok\",\"c\":[\"text1\",\"text2\",\"text3\"]}]";
This is as if it cant see the second object
parse :
[{"a":"ok","c":["text1","text2","text3"]},{"a":"ok","c":["text1","text2","text3"]}]
r : 0
a: ok
c 0: text1
c 1: text2
c 2: text3
c 3:
c 4:
c 5: ��D��
c 6:
c 7:
c 8:
c 9: =��
c 10: � K" p����
c 11:
c 12:
c 13: J{#��=,
c 14:
c 15: ����o���
c 16: ok
c 17: text1
c 18: text2
c 19: text3
c 20:
c 21:
c 22:
c 23:
c 24:
c 25: �D�
c 26: T
c 27: �z
c 28: E: ***** BUS FAULT *****
E: Precise data bus error
E: BFAR Address: 0xad9f9fac
E: r0/a1: 0xad9f9fac r1/a2: 0x00000000 r2/a3: 0x0001d770
E: r3/a4: 0xad9f9fac r12/ip: 0x20002ce1 r14/lr: 0x0001d7ed
E: xpsr: 0xa1000000
E: Faulting instruction address (r15/pc): 0x00018274
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
Have an idea?
Thanks !