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

@ -32,12 +32,12 @@ void loadConfiguration(const char *filename, Config &config) {
// Allocate the memory pool on the stack.
// Don't forget to change the capacity to match your JSON document.
// Use arduinojson.org/assistant to compute the capacity.
StaticJsonBuffer<512> jsonBuffer;
StaticJsonObject<512> root;
// Parse the root object
JsonObject &root = jsonBuffer.parseObject(file);
bool success = deserializeJson(root, file);
if (!root.success())
if (!success)
Serial.println(F("Failed to read file, using default configuration"));
// Copy values from the JsonObject to the Config
@ -65,10 +65,7 @@ void saveConfiguration(const char *filename, const Config &config) {
// Allocate the memory pool on the stack
// Don't forget to change the capacity to match your JSON document.
// Use https://arduinojson.org/assistant/ to compute the capacity.
StaticJsonBuffer<256> jsonBuffer;
// Parse the root object
JsonObject &root = jsonBuffer.createObject();
StaticJsonObject<256> root;
// Set the values
root["hostname"] = config.hostname;
@ -141,4 +138,4 @@ void loop() {
// The book "Mastering ArduinoJson" contains a case study of a project that has
// a complex configuration with nested members.
// Contrary to this example, the project in the book uses the SPIFFS filesystem.
// Please check it out at: https://arduinojson.org/book/
// Please check it out at: https://arduinojson.org/book/