Updated Examples (markdown)

acasadoalonso
2015-07-27 16:28:07 +02:00
parent 04c33afe3c
commit 6757a017aa

@@ -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.