Replace the examples with the new API

This commit is contained in:
Benoit Blanchon
2014-07-31 20:33:12 +02:00
parent 84aa627038
commit 2771b830b7

View File

@ -27,9 +27,9 @@ Example
array.add<6>(2.302038); array.add<6>(2.302038);
JsonObject<3> root; JsonObject<3> root;
root.add("sensor", "gps"); root["sensor"] = "gps";
root.add("time", 1351824120); root["time"] = 1351824120;
root.add("data", array); root["data"] = array;
Serial.print(root); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} Serial.print(root); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
@ -111,24 +111,24 @@ Like with the array class, there is a template parameter that gives the capacity
Then you can add strings, integer, booleans, etc: Then you can add strings, integer, booleans, etc:
object.add("key1", "bazinga!"); object["key1"] = "bazinga!";
object.add("key2", 42); object["key2"] = 42;
object.add("key3", true); object["key3"] = true;
As for the arrays, there are two syntaxes for the floating point values: As for the arrays, there are two syntaxes for the floating point values:
array.add<4>("key4", 3.1415); // 4 digits: "3.1415" object["key4"].set<4>(3.1415); // 4 digits "3.1415"
array.add("key5", 3.14); // 2 digits: "3.14" object["key5"] = 3.1415; // default: 2 digits "3.14"
Finally you can add nested objects: Finally you can add nested objects:
JsonArray<8> nestedArray; JsonArray<8> nestedArray;
object.add("key6", nestedArray); object["key6"] = nestedArray;
or or
JsonObject<8> nestedObject; JsonObject<8> nestedObject;
object.add("key7", nestedObject); object["key7"] = nestedObject;
### 4. Get the JSON string ### 4. Get the JSON string