Don't use JsonBuffer to create or parse objects and arrays.

* Added DynamicJsonArray and StaticJsonArray
* Added DynamicJsonObject and StaticJsonObject
* Added DynamicJsonVariant and StaticJsonVariant
* Added deserializeJson()
* Removed JsonBuffer::parseArray(), parseObject() and parse()
* Removed JsonBuffer::createArray() and createObject()
This commit is contained in:
Benoit Blanchon
2018-02-26 16:05:16 +01:00
parent baf5adcf33
commit 7a2a64803a
89 changed files with 1612 additions and 1691 deletions

View File

@ -11,17 +11,17 @@ void setup() {
Serial.begin(9600);
while (!Serial) continue;
// Memory pool for JSON object tree.
// Root JSON object
//
// Inside the brackets, 200 is the size of the pool in bytes.
// Inside the brackets, 200 is the size of the memory pool in bytes.
// Don't forget to change this value to match your JSON document.
// Use arduinojson.org/assistant to compute the capacity.
StaticJsonBuffer<200> jsonBuffer;
StaticJsonObject<200> root;
// StaticJsonBuffer allocates memory on the stack, it can be
// replaced by DynamicJsonBuffer which allocates in the heap.
// StaticJsonObject allocates memory on the stack, it can be
// replaced by DynamicJsonObject which allocates in the heap.
//
// DynamicJsonBuffer jsonBuffer(200);
// DynamicJsonObject root(200);
// JSON input string.
//
@ -36,10 +36,10 @@ void setup() {
// It's a reference to the JsonObject, the actual bytes are inside the
// JsonBuffer with all the other nodes of the object tree.
// Memory is freed when jsonBuffer goes out of scope.
JsonObject& root = jsonBuffer.parseObject(json);
bool success = deserializeJson(root, json);
// Test if parsing succeeds.
if (!root.success()) {
if (!success) {
Serial.println("parseObject() failed");
return;
}
@ -75,4 +75,4 @@ void loop() {
// The book "Mastering ArduinoJson" contains a tutorial on deserialization.
// It begins with a simple example, like the one above, and then adds more
// features like deserializing directly from a file or an HTTP request.
// Please check it out at: https://arduinojson.org/book/
// Please check it out at: https://arduinojson.org/book/