-
Notifications
You must be signed in to change notification settings - Fork 72
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
change json inplace #25
Comments
I changed the const_iterator to iterator in Child and added SetNumber (because I need to change number inside JSONObject), now its sort of inplace.. I have to use JSONValue * everywhere and use only Child() to access "nested" structures.
I hope that I am not reinventing the wheel.. but it works for me.. |
I have similar issue, I need to add key-value to "JSONObject". I have both variants: const JSONObject &JSONValue::AsObject() const
{
return (*object_value);
}
JSONObject &JSONValue::AsObject()
{
return (*object_value);
} and your SetNumber function alikes. |
@karelv have you got an example of what you're trying to do? Running the following through valgrind gives no memory leaks... int main(int arc, char ** argv) {
JSONObject obj;
obj[L"foo"] = new JSONValue(L"bar");
obj[L"pi"] = new JSONValue(3.141);
JSONValue *json = new JSONValue(obj);
std::wcout << json->Stringify() << std::endl;
delete json;
return 0;
} |
Hi,
I am trying to implement function to get json, change some part of it and return the changed json.
I thought that its easy.. just parse the json, cast it with AsObject AsArray etc.. change the values inside and then call Stringify on root JSONValue..
But then I found out that the AsObject/AsArray functions are returing const reference which cannot be changed.
I thought that I will use JSONValue::Child() for that but I am not sure if it would work for ::Child(wchar_t*) because there is some const_iterator used..
Is there any way how to achieve inplace change of json easily?
Maybe I overlook/misunderstood something.. sorry for dumb question opening issue..
Also regarding the Child() methods .. why do you not overload subscript [] operator?
Maybe in that way we could just check whats inside JSONValue and go on with [] which would make things easier.. now I have to do the casts all the time which makes it harder to read..
Thanks for your work, I am glad that I do not have to do json stuff myself.. and also your lib compiles on Win XP SP1 which is (sadly) requirement for me :D
The text was updated successfully, but these errors were encountered: