Added StaticJsonDocument and DynamicJsonDocument.

Removed StaticJsonArray and DynamicJsonArray.
Removed StaticJsonObject and DynamicJsonObject.
Removed StaticJsonVariant and DynamicJsonVariant.
This commit is contained in:
Benoit Blanchon
2018-04-17 21:27:45 +02:00
parent a13b9e8bdc
commit 1feb92679d
100 changed files with 1696 additions and 1844 deletions

View File

@ -70,19 +70,21 @@ void setup() {
return;
}
// Allocate JsonBuffer
// Allocate the JSON document
// Use arduinojson.org/assistant to compute the capacity.
const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
DynamicJsonObject root(capacity);
DynamicJsonDocument doc(capacity);
// Parse JSON object
JsonError error = deserializeJson(root, client);
JsonError error = deserializeJson(doc, client);
if (error) {
Serial.println(F("Parsing failed!"));
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
// Extract values
JsonObject& root = doc.as<JsonObject>();
Serial.println(F("Response:"));
Serial.println(root["sensor"].as<char*>());
Serial.println(root["time"].as<char*>());