-
-
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
How to create a json object from a std::string, created by j.dump? #1645
Comments
As stated in Serialization / Deserialization section of README, you can use |
Thanks for getting back to me.
I am getting this:
Should I be checking that the string is valid somehow? Thanks again |
As demonstrated in README, you should use the static auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }"); Nevertheless, the error you mentioned indicates that the string is empty. You should make sure it doesn't contains invalid characters (e.g. |
thank you! one more quick thing... My string is:
and i get:
What is the approach to get the array from a json like this? Thanks! |
Maybe because You should prefer explicit type conversion. e.g.: auto timecode = json["timecode"].get<std::vector<int>>(); Also, you don't have to iterate over the keys for retriering their values. You can directly access them (just like above). There is also APIs to check for presence of a key (e.g. |
ah that is a much nicer way to do it! Thank you very much for your time. |
What is the difference between the non-static parse() and static parse()? In other words, when should we use non-static parse() as opposed to the static parse()? |
There is no nonstatic parse method. |
Hi, thank you very much for this library.
I am sending a json over UDP.
I create it like this:
I dump it to a string:
std::string s = j.dump();
and send it:
client.send(s);
When I receive it, it's as a std::string.
std::string data_;
It looks correct.
Now, i want to create a json object from this string that matches the one i sent.
json j2 = data_;
How can i do this?
Thank you.
The text was updated successfully, but these errors were encountered: