Home > Blockchain >  how can i get an object inside another object "JSON" using json-c?
how can i get an object inside another object "JSON" using json-c?

Time:01-29

i am currently using json-c (https://github.com/json-c/json-c) to get the first name i get it as such

struct json_object *name;
json_object_object_get_ex(parsed_json, "name", &name);
{
name: "adriana",
lastName:{
          firstLastName: "doe",
          secondLastname: "doetwo"
            }
}

how do i get the firstLastName & secondLastname?

CodePudding user response:

basically you just re-pass the saved result in this case is last_name so..

struct json_object *last_name;
struct json_object *firstLastName;
struct json_object *secondLastName;
json_object_object_get_ex(last_name, "firstLastName", &firstLastName);

//and for the secondLastName

json_object_object_get_ex(last_name, "secondLastName", &secondLastName);

  •  Tags:  
  • Related