Arduino example are now compiling

This commit is contained in:
Benoit Blanchon
2014-11-03 21:29:55 +01:00
parent d9cc259df3
commit 699292b058
5 changed files with 104 additions and 84 deletions

View File

@ -1,32 +1,43 @@
/*
* Arduino JSON library - Generator example
* Benoit Blanchon 2014 - MIT License
*/
// Copyright Benoit Blanchon 2014
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#include <JsonGenerator.h>
#include <ArduinoJson.h>
using namespace ArduinoJson::Generator;
void setup() {
Serial.begin(9600);
void setup()
{
Serial.begin(9600);
StaticJsonBuffer<200> jsonBuffer;
JsonArray<2> array;
array.add<6>(48.756080); // 6 is the number of decimals to print
array.add<6>(2.302038); // if not specified, 2 digits are printed
JsonArray& array = jsonBuffer.createArray();
array.add(48.756080, 6); // 6 is the number of decimals to print
array.add(2.302038, 6); // if not specified, 2 digits are printed
JsonObject<3> root;
root["sensor"] = "gps";
root["time"] = 1351824120;
root["data"] = array;
JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = 1351824120;
root["data"] = array;
Serial.print(root); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
root.printTo(Serial);
// This prints:
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
Serial.println();
root.prettyPrintTo(Serial); // same string indented
Serial.println();
root.prettyPrintTo(Serial);
// This prints:
// {
// "sensor": "gps",
// "time": 1351824120,
// "data": [
// 48.756080,
// 2.302038
// ]
// }
}
void loop()
{
void loop() {
// not used in this example
}