cJSON
cJSON copied to clipboard
Feature: array of objects
After searching the library for a while, I did not find an API to be able to create an array of objects to obtain something like I show below
{
"property" : "value",
"array": [
{
"object1": {
"prop_obj1": value,
"prop_obj2": value,
"prop_obj3": value
}
},
{
"object2": {
"prop_obj1": value,
"prop_obj2": value,
"prop_obj3": value
}
},
{
"object3": {
"prop_obj1": value,
"prop_obj2": value,
"prop_obj3": value
}
}
]
}
You probably can by using different functions, check out this example code. There's one using helper functions and one not. The way I see you could do this is the following.
- generate an empty json object
- add object to base empty json_object and add name 'property' with value.
-
array
cJSON data structure. add empty array to json_object - for each
object
(object1,2,3..), add an empty object array toarray
with the object name, then another array inside it with the properties you list