You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if there is a reason that a call to parse on a json object just returns a null json object? The same input seems to parse without issue using the jason::parse call.
In the upper example, you create a json object j which is initially null. In line 4, you basically call the static function json::parse(input); which returns the result of the deserialization. As this result is not stored, j remains unchanged. In line 6, you make the same call, but store the result in j, yielding the expected result.
Again: parse is not a member function, but a static function. Calling it as a member function is syntactically OK, but does not change the object you call it from.
The parse function is static. There is no such thing as calling it "on an object", except that C++ allows you to identify the static function to call using an object instead of the class name.
Your code is equivalent to this:
Activity
nlohmann commentedon Nov 9, 2016
In the upper example, you create a
jsonobjectjwhich is initiallynull. In line 4, you basically call the static functionjson::parse(input);which returns the result of the deserialization. As this result is not stored,jremains unchanged. In line 6, you make the same call, but store the result inj, yielding the expected result.Again:
parseis not a member function, but a static function. Calling it as a member function is syntactically OK, but does not change the object you call it from.gregmarr commentedon Nov 9, 2016
The parse function is static. There is no such thing as calling it "on an object", except that C++ allows you to identify the static function to call using an object instead of the class name.
Your code is equivalent to this:
gregmarr commentedon Nov 9, 2016
Heh, I saw @nlohmann's answer appear just as I clicked the Comment button. :)
nlohmann commentedon Nov 9, 2016
Same here, but Github claims I was 3 seconds faster ;)
oneill1979 commentedon Nov 9, 2016
Ah, thank you. I had not noticed that it was a static method.