JsonGeneratorExample.ino 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #include <ArduinoJson.h>
  7. void setup() {
  8. Serial.begin(9600);
  9. StaticJsonBuffer<200> jsonBuffer;
  10. JsonObject& root = jsonBuffer.createObject();
  11. root["sensor"] = "gps";
  12. root["time"] = 1351824120;
  13. JsonArray& data = root.createNestedArray("data");
  14. data.add(double_with_n_digits(48.756080, 6));
  15. data.add(double_with_n_digits(2.302038, 6));
  16. root.printTo(Serial);
  17. // This prints:
  18. // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
  19. Serial.println();
  20. root.prettyPrintTo(Serial);
  21. // This prints:
  22. // {
  23. // "sensor": "gps",
  24. // "time": 1351824120,
  25. // "data": [
  26. // 48.756080,
  27. // 2.302038
  28. // ]
  29. // }
  30. }
  31. void loop() {
  32. // not used in this example
  33. }