-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Adding keys to object in a loop #84
Comments
Hi Sean, This is a tough one. Several users felt into this trap (see #10, #57). The reason is that, for performance reasons, ArduinoJson never makes copies of the strings. It may look strange if you come from Java or C#, but C++ works that way. The solution is to allocate the memory outside of the loop. Here is a suggestion:
You should also consider using a Thanks for using the beta version, this is really helping me 😉 Regards, |
That worked - thanks very much! This has indeed exposed my lack of C++ exposure. May I suggest that the wiki contains a small warning about this? So far everything in 5.0beta1 is working as expected - good job! |
I added section 6. Do not assume that strings are copied. |
Thanks, will do! |
I am having trouble adding keys to a JsonObject within a loop:
This outputs on the serial terminal:
So only the last iteration of the loop is added to the object. I guess the same value is being overwritten in each iteration, but I can't figure out why.
I'm using v5.0beta1. I know you don't encourage the use of String() but I tried to figure out a way to do this with chars and it was even less successful (meaningless garbage was printed, mostly).
Any help would be greatly appreciated! This is an excellent tool - thanks a lot for sharing it.
The text was updated successfully, but these errors were encountered: