i am trying to parse a json array,i am facing problem.
My array is like this:
configure: {
"id": 4,
"userId": 107,
"deviceMacAddress": "00:06:66:30:02:3C",
"medication": [{
"id": 11,
"version": 18,
"name": "name1",
"unit": "mg",
"forMed": "for1",
"schedule": [1]
}, {
"id": 45,
"version": 1,
"name": "sdga",,
"unit": "mg",
"forMed": "54234",
"schedule": [0,1,2,3,4,5,6]
}],
i am able to access medication array and print total array,but not able to access objects inside array. can you pls suggest any solution or any example to do this using C language?
MyCode
int main(int argc, char **argv) {
struct json_object *med_obj, *medi_obj, *tmp1_obj;
struct array_list *lArray;
charname[10] = {0};
static const char filename[] = "xyz.txt";
med_obj = json_object_from_file(filename);
medi_obj = json_object_object_get(med_obj, "medication");
lArray = json_object_get_array(medi_obj);
tmp1_obj = json_object_object_get(medi_obj, "name");
strcpy (name,json_object_to_json_string(tmp1_obj));
printf("name=%s\n",name);
}
Regards, Lenin.
You need to access the inner array using a
json_object *
variable.Try this:
You can use any YAML parsing library, look here for example.
You can use the jsoncpp to do this job. Array as a Json::Value, you can
I hope will help you.
If you want to access the array as a json object, you should get it as a json_object* but not a array_list*