-
-
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
How to use createNestedObject in a for loop? #87
Comments
If you're function is written like that:
then you're leaking two dangling pointers to Here is an suggestion using the builder pattern:
|
Thanks bblanchon for your detailed response. Yes, my function is currently written like it shouldn't be. So you are saying it is required to use a class to achieve this? This would increase complexity of my Arduino sketch significantly and I might be tempted to fall back to using Strings ;-). |
Here is another suggestion using the memory from the
Don't forget to increase the size of the |
Thanks bblanchon. I realize this is an issues tracker and not a C programming course, but maybe you are interested in the real-world problems users of your library are facing, hence I go ahead and fully respect if you won't answer. Your example works well for the short sample but my actual function looks like
I would be quite tedious to do all the memory allocation by hand. Or is your library not really suitable for doing things like that and you would advise to go another route like using Strings instead? (In case you are wondering what I am trying to do: https://github.com/probonopd/ESP8266HueEmulator/tree/ArduinoJson) |
There are again several dangling pointers here. I personally hate the Arduino Now that I know the complexity of the task, I would recommend the builder pattern again.
Anyway, you opened my eyes on the necessity to be able to easily duplicate strings. PS: please add your project to the wiki: https://github.com/bblanchon/ArduinoJson/wiki/Projects%20using%20ArduinoJson |
I added the feature in version 5.0 beta 3. Now Your code can now be written as:
(I just removed the Don't hesitate to re-open the issue if there is a problem. |
Thank you very much for your explanation. Appreciate it. |
Spent some time trying to fix a leaky pointer issue and creating a |
Hi @andrei-ivanov. |
Hmm, not sure I can... but my |
Sorry for bringing up one more question similar to #10, #57, #84 but this appears to be strange for beginners.
I am trying to generate
using a function
addLight(root, i)
that I need to call for a dynamic number i of lights which is determined at runtime (in the above example, i is 1...999). Looking at https://arduinojson.org/doc/pitfalls/#6-do-not-assume-that-strings-are-copied I am pretty certain that what I am doing right now is entirely wrong (and the result is a crash) but I cannot quite figure out what I need to do instead.The text was updated successfully, but these errors were encountered: