mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-17 19:41:16 +02:00
Updated Examples (markdown)
32
Examples.md
32
Examples.md
@@ -1,3 +1,34 @@
|
||||
## Example 2: get the weather data from aviationweather.gov or geonames.org
|
||||
char *MTserverName = "api.geonames.org"; // server name
|
||||
String cmd = "GET /weatherIcaoJSON?ICAO="; // prepare the command to send to the web server after
|
||||
|
||||
getting the data on JSON format and parsing the buffer:
|
||||
|
||||
|
||||
JsonObject& _root = jsonBuffer.parseObject(MTjson); // parse the JSON buffer
|
||||
|
||||
if (!_root.success()) { // everything OK
|
||||
Serial.println("MTparseObject() failed");
|
||||
delay(10000);
|
||||
__wferrno=-2; // set the error code
|
||||
return NULL;
|
||||
}
|
||||
if (Debug&&Debugplus) Serial.println("Beauty print...");
|
||||
if (Debug&&Debugplus) _root.prettyPrintTo(Serial); // print it on prettyPrint format
|
||||
if (Debug&&Debugplus) Serial.println("END of Beauty print...");
|
||||
|
||||
JsonObject & _ooo = _root["weatherObservation"]; // query root
|
||||
MET->MTobservation = _ooo ["observation"]; // raw observation
|
||||
MET->MTtemp = _ooo ["temperature"]; // temp
|
||||
MET->MTpressure = _ooo ["hectoPascAltimeter"]; // QNH
|
||||
MET->MTQNH = _ooo ["hectoPascAltimeter"]; // QNH
|
||||
MET->MTdewpoint = _ooo ["dewPoint"]; // Dew point
|
||||
MET->MThumidity = _ooo ["humidity"]; // humidity %
|
||||
MET->MTwinddeg = _ooo ["windDirection"]; // wind
|
||||
MET->MTwindspeed = _ooo ["windSpeed"]; // speed
|
||||
MET->MTobservationtime= _ooo ["datetime"]; // time
|
||||
|
||||
|
||||
## Example 1: complex nested object
|
||||
|
||||
From [issue #85](https://github.com/bblanchon/ArduinoJson/issues/85):
|
||||
@@ -23,4 +54,3 @@ Can be generated by the following code:
|
||||
root.prettyPrintTo(Serial);
|
||||
|
||||
Don't forget to replace the `DynamicJsonBuffer` by a `StaticJsonBuffer` if you need to run on an embedded platform like an Arduino.
|
||||
|
||||
|
Reference in New Issue
Block a user