mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Added StaticJsonDocument and DynamicJsonDocument.
Removed StaticJsonArray and DynamicJsonArray. Removed StaticJsonObject and DynamicJsonObject. Removed StaticJsonVariant and DynamicJsonVariant.
This commit is contained in:
		| @@ -12,17 +12,17 @@ void setup() { | ||||
|   Serial.begin(9600); | ||||
|   while (!Serial) continue; | ||||
|  | ||||
|   // Root JSON object | ||||
|   // Allocate the JSON document | ||||
|   // | ||||
|   // 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. | ||||
|   StaticJsonObject<200> root; | ||||
|   StaticJsonDocument<200> doc; | ||||
|  | ||||
|   // StaticJsonObject allocates memory on the stack, it can be | ||||
|   // replaced by DynamicJsonObject which allocates in the heap. | ||||
|   // | ||||
|   // DynamicJsonObject  root(200); | ||||
|   // DynamicJsonObject doc(200); | ||||
|  | ||||
|   // MessagePack input string. | ||||
|   // | ||||
| @@ -40,23 +40,27 @@ void setup() { | ||||
|   //   "data": [48.75608, 2.302038] | ||||
|   // } | ||||
|  | ||||
|   // Root of the object tree. | ||||
|   // doc of the object tree. | ||||
|   // | ||||
|   // 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. | ||||
|   MsgPackError error = deserializeMsgPack(root, input); | ||||
|   MsgPackError error = deserializeMsgPack(doc, input); | ||||
|  | ||||
|   // Test if parsing succeeds. | ||||
|   if (error) { | ||||
|     Serial.println("deserializeMsgPack() failed"); | ||||
|     Serial.print("deserializeMsgPack() failed: "); | ||||
|     Serial.println(error.c_str()); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   // Get the root object in the document | ||||
|   JsonObject& root = doc.as<JsonObject>(); | ||||
|  | ||||
|   // Fetch values. | ||||
|   // | ||||
|   // Most of the time, you can rely on the implicit casts. | ||||
|   // In other case, you can do root["time"].as<long>(); | ||||
|   // In other case, you can do doc["time"].as<long>(); | ||||
|   const char* sensor = root["sensor"]; | ||||
|   long time = root["time"]; | ||||
|   double latitude = root["data"][0]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user