|
1 |
| -# jsonlib |
2 |
| -Simple JSON parsing library |
| 1 | +jsonlib |
| 2 | +======= |
| 3 | +Simple JSON parsing library for arduino |
| 4 | + |
| 5 | +## Usage example |
| 6 | + |
| 7 | +```c++ |
| 8 | + String posStr = jsonExtract(json, "coord"); // {"lon":-77.35,"lat":38.93} |
| 9 | + float lat = jsonExtract(posStr, "lat").toFloat(); // 38.93 |
| 10 | + float lon = jsonExtract(posStr, "lon").toFloat(); // -77.35 |
| 11 | + String weather_list = jsonExtract(json, "weather"); // [{"id":500,"main":"Rain","description":"light rain","icon":"10d"}] |
| 12 | + Serial.print("weather_list:"); |
| 13 | + Serial.println(weather_list); |
| 14 | + String weather_0 = jsonIndexList(weather_list, 0); // {"id":500,"main":"Rain","description":"light rain","icon":"10d"} |
| 15 | + Serial.print("weather_0:"); |
| 16 | + Serial.println(weather_0); |
| 17 | + String desc = jsonExtract(weather_0, "description"); // light rain |
| 18 | + Serial.printf("Location:%f,%f. Current conditions: %s", lat, lon, desc.c_str()); |
| 19 | +``` |
| 20 | + |
| 21 | +## Reference |
| 22 | + |
| 23 | +### jsonExtract |
| 24 | + |
| 25 | +```c++ |
| 26 | +String jsonIndexList(String json, int idx); |
| 27 | +``` |
| 28 | +
|
| 29 | +Returns a String containing indexed item from provided String containing a json object. |
| 30 | +
|
| 31 | +```c++ |
| 32 | +String jsonExtract(String json, String name); |
| 33 | +``` |
| 34 | + |
| 35 | +Returns a String containing the named item from provided String containing a json object. |
| 36 | +Adds a custom time when the sun reaches the given angle to results returned by `SunCalc.getTimes`. |
0 commit comments