Arduino Library – ArduinoJson
Installatie van Arduino IDE libraries: Arduino info
Informatie (ENG):
Arduino JSON library
An elegant and efficient JSON library for embedded systems.
It’s designed to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc).
It has been written with Arduino in mind, but it isn’t linked to Arduino libraries so you can use this library in any other C++ project.
- JSON decoding (comments are supported)
- JSON encoding (with optional indentation)
- Elegant API, very easy to use
- Fixed memory allocation (zero malloc)
- No data duplication (zero copy)
- Portable (written in C++98)
- Self-contained (no external dependency)
- Small footprint
- MIT License
- All Arduino boards (Uno, Due, Mini, Micro, Yun…)
- ESP8266
- Teensy
- Intel Edison
- PlatformIO
- Energia
- RedBearLab boards (BLE Nano…)
- Computers (Windows, Linux, OSX…)
Decoding / Parsing
1 2 3 4 5 6 7 8 9 10 |
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; StaticJsonBuffer<200> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(json); const char* sensor = root["sensor"]; long time = root["time"]; double latitude = root["data"][0]; double longitude = root["data"][1]; |
Encoding / Generating
1 2 3 4 5 6 7 8 9 10 11 12 13 |
StaticJsonBuffer<200> jsonBuffer; JsonObject& root = jsonBuffer.createObject(); root["sensor"] = "gps"; root["time"] = 1351824120; JsonArray& data = root.createNestedArray("data"); data.add(48.756080, 6); // 6 is the number of decimals to print data.add(2.302038, 6); // if not specified, 2 digits are printed root.printTo(Serial); // This prints: // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} |
The documentation is available online in the Arduino JSON wiki
Download ArduinoJson @ github.com
[#/arduino/libraries/arduinojson” ]