Added JsonArray iterator

Benoît Blanchon
2015-09-01 08:23:37 +02:00
parent f4520a27b6
commit ad14662169

@@ -1,3 +1,29 @@
## Example 1: complex nested object
From [issue #85](https://github.com/bblanchon/ArduinoJson/issues/85):
[
{
"error": {
"address": "",
"description": "link button not pressed",
"type": "101"
}
}
]
Can be generated by the following code:
DynamicJsonBuffer jsonBuffer;
JsonArray& root = jsonBuffer.createArray();
JsonObject& error = root.createNestedObject().createNestedObject("error");
error["address"] = "";
error["description"] = "link button not pressed";
error["type"] = "101";
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.
## 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
@@ -28,29 +54,16 @@ getting the data on JSON format and parsing the buffer:
MET->MTwindspeed = _ooo ["windSpeed"]; // speed
MET->MTobservationtime= _ooo ["datetime"]; // time
## Example 3: use iterators
## Example 1: complex nested object
From [issue #85](https://github.com/bblanchon/ArduinoJson/issues/85):
```c++
JsonArray & array;
[
{
"error": {
"address": "",
"description": "link button not pressed",
"type": "101"
}
}
]
Can be generated by the following code:
DynamicJsonBuffer jsonBuffer;
JsonArray& root = jsonBuffer.createArray();
JsonObject& error = root.createNestedObject().createNestedObject("error");
error["address"] = "";
error["description"] = "link button not pressed";
error["type"] = "101";
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.
for(JsonArray::iterator it=array.begin(); it!=array.end(); ++it) {
const char* value = *it;
Serial.println(value);
// or
Serial.println(it->as<const char*>());
}
```