-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[answered]Read key1 from .value example #914
Comments
Assume you read this JSON value: {
"key1": true,
"key2": 2
} Then you can access the values with: bool k1 = j["key1"];
int k2 = j["key2"]; (assuming you parsed your JSON value to If you need more information, please provide some example code, the error you experience and your expected behavior. |
I get a json in a string from a http post `std::string input=
and after that I parse them like this so I get rid of the backslash: and I am reading values at the same level as str or int by making:
but what do I have to do If I want to read key1/2 or subkey1/2? EDIT And is there any difference between |
|
"but what do I have to do If I want to read key1/2 or subkey1/2?" If you want to read a subkey you could access the json object as it is like a multilevel array: int value = j["object"]["subobject"][subkey1].get<int>(); Or by walk throw in a STL manner: for (json::iterator it = j["object"].begin(); it != j["object"].end(); ++it) {
std::cout << it.key() << " : " << it.value() << "\n";
} But with a loop you would need to interact each subobject in a nested loop! |
I have finally made it like this:
So I check if it exists, and then I read it. Thank you very much for your help |
I was trying to use the library to read and parse a json post which I receive, so I just want to read each value, but , I dont know how to read a value inside an object. In this example I would like to access the value of key1 or key2, I have tryed things like object.key1 or object:key1, but none of them worked.
The text was updated successfully, but these errors were encountered: