mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Arduino example are now compiling
This commit is contained in:
		| @@ -3,41 +3,28 @@ | ||||
|  * Benoit Blanchon 2014 - MIT License | ||||
|  */ | ||||
|  | ||||
| #include <JsonGenerator.h> | ||||
| #include <ArduinoJson.h> | ||||
|  | ||||
| using namespace ArduinoJson::Generator; | ||||
| using namespace ArduinoJson::Internals; | ||||
|  | ||||
| void setup() | ||||
| { | ||||
|     Serial.begin(9600); | ||||
|      | ||||
|     JsonObject<1> json; | ||||
|     json["key"] = "value"; | ||||
|      | ||||
|     IndentedPrint serial(Serial);     | ||||
|     serial.setTabSize(4); | ||||
|      | ||||
|     serial.println("This is at indentation 0"); | ||||
|     serial.indent(); | ||||
|     serial.println("This is at indentation 1"); | ||||
|     serial.println("This is also at indentation 1"); | ||||
|     serial.indent(); | ||||
|     serial.println("This is at indentation 2"); | ||||
|      | ||||
|     serial.println("You can print JSON here, as usual:"); | ||||
|     serial.println(json); | ||||
|     serial.println(); | ||||
|          | ||||
|     serial.println("But you can also prettyPrint JSON here:"); | ||||
|     json.prettyPrintTo(serial);   | ||||
|     serial.println(); | ||||
|      | ||||
|     serial.unindent(); | ||||
|     serial.unindent(); | ||||
|     serial.println("This is back at indentation 0"); | ||||
| void setup() { | ||||
|   Serial.begin(9600); | ||||
|  | ||||
|   IndentedPrint serial(Serial); | ||||
|   serial.setTabSize(4); | ||||
|  | ||||
|   serial.println("This is at indentation 0"); | ||||
|   serial.indent(); | ||||
|   serial.println("This is at indentation 1"); | ||||
|   serial.println("This is also at indentation 1"); | ||||
|   serial.indent(); | ||||
|   serial.println("This is at indentation 2"); | ||||
|  | ||||
|   serial.unindent(); | ||||
|   serial.unindent(); | ||||
|   serial.println("This is back at indentation 0"); | ||||
| } | ||||
|  | ||||
| void loop() | ||||
| { | ||||
|  | ||||
| void loop() { | ||||
|   // not used in this example | ||||
| } | ||||
| @@ -1,32 +1,43 @@ | ||||
| /* | ||||
|  * Arduino JSON library - Generator example | ||||
|  * Benoit Blanchon 2014 - MIT License | ||||
|  */ | ||||
| // Copyright Benoit Blanchon 2014 | ||||
| // MIT License | ||||
| // | ||||
| // Arduino JSON library | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
|  | ||||
| #include <JsonGenerator.h> | ||||
| #include <ArduinoJson.h> | ||||
|  | ||||
| using namespace ArduinoJson::Generator; | ||||
| void setup() { | ||||
|   Serial.begin(9600); | ||||
|  | ||||
| void setup() | ||||
| { | ||||
|     Serial.begin(9600); | ||||
|   StaticJsonBuffer<200> jsonBuffer; | ||||
|  | ||||
|     JsonArray<2> array; | ||||
|     array.add<6>(48.756080); // 6 is the number of decimals to print | ||||
|     array.add<6>(2.302038);  // if not specified, 2 digits are printed | ||||
|   JsonArray& array = jsonBuffer.createArray(); | ||||
|   array.add(48.756080, 6);  // 6 is the number of decimals to print | ||||
|   array.add(2.302038, 6);   // if not specified, 2 digits are printed | ||||
|  | ||||
|     JsonObject<3> root;  | ||||
|     root["sensor"] = "gps"; | ||||
|     root["time"] = 1351824120; | ||||
|     root["data"] = array; | ||||
|   JsonObject& root = jsonBuffer.createObject(); | ||||
|   root["sensor"] = "gps"; | ||||
|   root["time"] = 1351824120; | ||||
|   root["data"] = array; | ||||
|  | ||||
|     Serial.print(root); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} | ||||
|   root.printTo(Serial); | ||||
|   // This prints: | ||||
|   // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} | ||||
|  | ||||
|     Serial.println(); | ||||
|     root.prettyPrintTo(Serial); // same string indented | ||||
|   Serial.println(); | ||||
|  | ||||
|   root.prettyPrintTo(Serial); | ||||
|   // This prints: | ||||
|   // { | ||||
|   //   "sensor": "gps", | ||||
|   //   "time": 1351824120, | ||||
|   //   "data": [ | ||||
|   //     48.756080, | ||||
|   //     2.302038 | ||||
|   //   ] | ||||
|   // } | ||||
| } | ||||
|  | ||||
| void loop() | ||||
| { | ||||
|  | ||||
| void loop() { | ||||
|   // not used in this example | ||||
| } | ||||
| @@ -1,40 +1,37 @@ | ||||
| /* | ||||
| * Arduino JSON library - Parser Example | ||||
| * Benoit Blanchon 2014 - MIT License | ||||
| */ | ||||
| // Copyright Benoit Blanchon 2014 | ||||
| // MIT License | ||||
| // | ||||
| // Arduino JSON library | ||||
| // https://github.com/bblanchon/ArduinoJson | ||||
|  | ||||
| #include <JsonParser.h> | ||||
| #include <ArduinoJson.h> | ||||
|  | ||||
| using namespace ArduinoJson::Parser; | ||||
| void setup() { | ||||
|   Serial.begin(9600); | ||||
|  | ||||
| void setup() | ||||
| { | ||||
|     Serial.begin(9600); | ||||
|   StaticJsonBuffer<200> jsonBuffer; | ||||
|  | ||||
|     char json [] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; | ||||
|   char json[] = | ||||
|       "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; | ||||
|  | ||||
|     JsonParser<16> parser; | ||||
|   JsonObject& root = jsonBuffer.parseObject(json); | ||||
|  | ||||
|     JsonObject root = parser.parse(json); | ||||
|   if (!root.success()) { | ||||
|     Serial.println("parseObject() failed"); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|     if (!root.success()) | ||||
|     { | ||||
|         Serial.println("JsonParser.parse() failed"); | ||||
|         return; | ||||
|     } | ||||
|   const char* sensor = root["sensor"]; | ||||
|   long time = root["time"]; | ||||
|   double latitude = root["data"][0]; | ||||
|   double longitude = root["data"][1]; | ||||
|  | ||||
|     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); | ||||
|   Serial.println(sensor); | ||||
|   Serial.println(time); | ||||
|   Serial.println(latitude, 6); | ||||
|   Serial.println(longitude, 6); | ||||
| } | ||||
|  | ||||
| void loop() | ||||
| { | ||||
|  | ||||
| void loop() { | ||||
|   // not used in this example | ||||
| } | ||||
		Reference in New Issue
	
	Block a user