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

The name of an object is lost when calling cJSON_ReplaceItemInObject() #174

Closed
claudiusaiz opened this issue May 22, 2017 · 3 comments
Closed
Labels

Comments

@claudiusaiz
Copy link

What I would like to do is replace a child object with another object:

new_child = cJSON_CreateObject();
cJSON_ReplaceItemInObject(parent, "child", new_child);

But the problem with this is that the name of the object gets lost after the replacement. I see that the name is not copied in cJSON_ReplaceItemViaPointer().

For those having the same problem an alternative to this is:

new_child = cJSON_CreateObject();
cJSON_DeleteItemFromObject(parent, "child");
cJSON_AddItemToObjectCS(parent, "child", new_child);

, with the disadvantage that the position of the object in the array will not be the same. The JSON standard says it shouldn't matter, but in the end it depends on the endpoint's parser implementation.

@FSMaxB FSMaxB added the bug label May 22, 2017
@FSMaxB
Copy link
Collaborator

FSMaxB commented May 22, 2017

This is a bug. This has been different in previous versions of cJSON.

@FSMaxB FSMaxB closed this as completed in 9ecc968 May 22, 2017
@FSMaxB
Copy link
Collaborator

FSMaxB commented May 22, 2017

Thanks for reporting!

@claudiusaiz
Copy link
Author

claudiusaiz commented May 23, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants