mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			797 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			797 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Copyright Benoit Blanchon 2014
 | |
| // MIT License
 | |
| //
 | |
| // Arduino JSON library
 | |
| // https://github.com/bblanchon/ArduinoJson
 | |
| 
 | |
| #include <ArduinoJson.h>
 | |
| 
 | |
| void setup() {
 | |
|   Serial.begin(9600);
 | |
| 
 | |
|   StaticJsonBuffer<200> jsonBuffer;
 | |
| 
 | |
|   char json[] =
 | |
|       "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
 | |
| 
 | |
|   JsonObject& root = jsonBuffer.parseObject(json);
 | |
| 
 | |
|   if (!root.success()) {
 | |
|     Serial.println("parseObject() failed");
 | |
|     return;
 | |
|   }
 | |
| 
 | |
|   const char* sensor = root["sensor"];
 | |
|   long time = root["time"];
 | |
|   double latitude = root["data"][0];
 | |
|   double longitude = root["data"][1];
 | |
| 
 | |
|   Serial.println(sensor);
 | |
|   Serial.println(time);
 | |
|   Serial.println(latitude, 6);
 | |
|   Serial.println(longitude, 6);
 | |
| }
 | |
| 
 | |
| void loop() {
 | |
|   // not used in this example
 | |
| } |