GithubHelp home page GithubHelp logo

List<JsonObject> about arduinojson HOT 9 CLOSED

bblanchon avatar bblanchon commented on September 26, 2024
List

from arduinojson.

Comments (9)

bblanchon avatar bblanchon commented on September 26, 2024

Hi,

To generate the following JSON:

[{"key1":"value1"},{"key2":"value2"}]

you need to create a JsonArray with two nested JsonObject:

StaticJsonBuffer<200> jsonBuffer;

JsonArray& array = jsonBuffer.createArray();

JsonObject& obj1 = array.createNestedObject();
obj1["key1"] = "value1";

JsonObject& obj2 = array.createNestedObject();
obj2["key2"] = "value2";

array.printTo(Serial);

Please keep in mind that this is a serialization library, not a high performance collection library.

In particular, there is no way to remove an element from an array.
Although this particular feature could easily be added, it would not be efficient in term of memory management because the library was not designed for that in the first place.

If you need to manipulate collection in you program, you should consider std::vector, then use ArduinoJson only for the serialization.

Regards,
Benoit

from arduinojson.

tiagotaz avatar tiagotaz commented on September 26, 2024

Thank you for answering my questions is working perfectly this way, only my questions about the removal of an array item that does not yet found a way to do.

from arduinojson.

bblanchon avatar bblanchon commented on September 26, 2024

Glad I could help.

I can easily add JsonArray::removeAt(int index) to remove an element in a array.
However, you must understand that the memory in the JsonBuffer will not be released.
It can be OK if you just remove one or two elements.
But if you need to remove elements repeatedly, it would be extremely inefficient.

Do you think that would be suitable for you?

from arduinojson.

tiagotaz avatar tiagotaz commented on September 26, 2024

Got it, really think that would be complicated, my idea was to create a temporary list that would be allocated objects and through the iterator they would be removed. now do not know what would be better option to dynamically work objects

Enviado do meu iPhone

Em 21/12/2014, às 15:01, Benoît Blanchon [email protected] escreveu:

It can be OK if you just remove one or two elements.
But if you need to remove elements repeatedly, it would be extremely inefficient.

Do you think that would be suitable for you?

from arduinojson.

bblanchon avatar bblanchon commented on September 26, 2024

Again, ArduinoJson is a library to serialize arrays and objects in JSON, I'm not sure it's really suitable for your needs.
If I were you, I would store that "temporary list" in a native array or a STL container like std::list or std::vector.

Can you disclose a little more information about your project?
I could try to give you better advices.

from arduinojson.

tiagotaz avatar tiagotaz commented on September 26, 2024

Hi,i need To implement the function remove can You help me ?

from arduinojson.

bblanchon avatar bblanchon commented on September 26, 2024

I added issue #58, I'll try to do that ASAP.

from arduinojson.

bblanchon avatar bblanchon commented on September 26, 2024

@tiagotaz: I added the JsonArray::removeAt() in the master branch. Sorry for the delay.

from arduinojson.

tiagotaz avatar tiagotaz commented on September 26, 2024

Great!!!!!!!!! very thank's

Tiago de Almeida
(11)9-8204-4454

2015-05-02 10:17 GMT-03:00 Benoît Blanchon [email protected]:

@tiagotaz https://github.com/tiagotaz: I added the
JsonArray::removeAt() in the master branch. Sorry for the delay.


Reply to this email directly or view it on GitHub
#38 (comment)
.

from arduinojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.