Skip to content

How to iterate over nested json object #1561

Description

@ezamosch

Hello.

I got json structure, which I need to parse:

{  
   "response":{  
      "count":207,
      "items":[  
         {  
            "id":262
         },
         {  
            "id":261
         }]
     }
}

In my c++ program I create json object from string with json:

using json = nlohmann::json;
json object = json::parse(json_param);

And then I need to iterate over respones.items. How propertly do this? I want to use 'for' operator:

for (auto it : object)
{
	std::cout << it["id"] << '\n';
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions