Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to iterate? #665

Closed
ghost opened this issue Jul 27, 2017 · 2 comments
Closed

How to iterate? #665

ghost opened this issue Jul 27, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 27, 2017

Hi, i couldn't figure out how to iterate over some simple json data like this:

string sJson=
			"{"
				"\"data\": ["
					"{"
						"\"id\": \"1000\""
					"},"
					"{"
						"\"id\": \"1001\""
					"},"
					"{"
						"\"id\": \"1002\""
					"}"
				"]"
			"}";

Please could you provide an example how to print all the ids?
In addition not being able to forward declare your stuff is a big show stopper.

@ghost
Copy link
Author

ghost commented Jul 27, 2017

Ok, i had to use

json j = json::parse(sJson);

instead of

json j = sJson;

The latter seems to add the sJson's text as a value to the json document.
After all this constructor doesn't make much sense for me...

@ghost ghost closed this as completed Jul 27, 2017
@nlohmann
Copy link
Owner

You could also use a user-defined string literal:

json j = R"(
{
  "key": "value",
  "another key": [1,2,3]
}
)"_json;

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant