-
-
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 cache a json object's pointer into a map? #1180
Comments
You can just use |
The title of my question might not accurate enough, actually I would like to know how to cache a json object's pointer into a map, like std::map<std::string, nlohmann::json *>
The code above is my changing based on previous CJSON logic, but I don't know how to write in the ??? place. |
You can cache a pointer to a json object in the map without a problem. The problem that you actually have is caching a pointer to an element of a vector whose size may change during the lifetime of the map. That is something that you can't do unless you've reserved enough space in the vector ahead of time such that it can never reallocate. What you could do is instead of caching a pointer to the object, cache a pointer to the parent and an index within the vector. So instead of |
@gregmarr Thank you so much! It works well to me. |
Hi, I have JSON file
It is generated by CJSON by the following code
m_content is a map to cache the GUID and its corresponding json object, the function AppendNode() could append an object into a json array but the function does not know how deep is the current object in the json file.
I would like to replace CJSON to json.hpp, but I don't know how to cache a json object into a map as value by json.hpp. Any ideas?
The text was updated successfully, but these errors were encountered: