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

strings can't be accessed after dump()->parse() - type is lost #281

Closed
guygman opened this issue Jul 13, 2016 · 1 comment
Closed

strings can't be accessed after dump()->parse() - type is lost #281

guygman opened this issue Jul 13, 2016 · 1 comment
Labels
solution: invalid the issue is not related to the library

Comments

@guygman
Copy link

guygman commented Jul 13, 2016

Hi,

strangely, this code doesn't work and I can't find out what I'm doing wrong....

nlohmann::json out;
out[accessTokenField] = (const string&)accessToken; // key and value std::strings
std::string tmp1 = out[accessTokenField]; // this works
std::string dump = out.dump(); // 'dump' is - {"accessToken": "b9c6f71f-0a10-4025-9628"}
nlohmann::json in;
in.parse(dump);
std::string tmp2 = in[accessTokenField]; // this fails!! error message- "type must be string, but is null"

update: using the static json::parse method works fine-
.
.
nlohmann::json in;
in = nlohmann::json::parse(dump);
std::string tmp2 = in[accessTokenField];

@nlohmann
Copy link
Owner

The parse function is static and returns the parsed JSON value. Instead of

in.parse(dump);

which does not alter in and leaves it as null, the code should read

in = nlohmann::json::parse(dump);

@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Jul 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants