Comments (9)
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.
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.
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.
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.
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.
Hi,i need To implement the function remove can You help me ?
from arduinojson.
I added issue #58, I'll try to do that ASAP.
from arduinojson.
@tiagotaz: I added the JsonArray::removeAt() in the master branch. Sorry for the delay.
from arduinojson.
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)
- V6 Documentation ArduinoJson PubSubClient with StreamUtils HOT 1
- deserialize file from LittleFS crash HOT 6
- Trying to compile a 2021 program HOT 2
- Bring back zero-copy mode in v7 HOT 6
- MQTT Publish destroying Json HOT 2
- Error compiling example code SimpleParser on Arduino Web Editor NodeMCU 0.9 HOT 1
- JSON output is truncated. HOT 1
- load an object into an absolute memory address, Cortex-M. HOT 4
- Cannot compile code that compiled last time it was used HOT 1
- There is a memory leak either in this library or in ESP32 LittleFS HOT 23
- Lint error ovl_no_viable_subscript has occured HOT 2
- Cleaning HTML Chuking Answer at the Custom Reader class for getting filtered JsonDocument HOT 1
- Return JsonDocument from class methods HOT 2
- Question - Access JSON data variables in nested arrays HOT 5
- Problem whith a JSON from Firefox to my ESP8266 HOT 3
- Capped Allocator HOT 4
- fatal error: ArduinoJson/Variant/VariantRefBase.hpp: No such file or directory HOT 1
- Example on ArduinoJson website crashes at runtime HOT 1
- ArduinoJson 7.1.0 Compile error [ invalid use of array with unspecified bounds ] HOT 2
- Missing links to specific types in the API reference HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinojson.