diff --git a/Quick-Start.md b/Quick-Start.md index 887a91c..2aa5b51 100644 --- a/Quick-Start.md +++ b/Quick-Start.md @@ -1,34 +1,38 @@ #include #### Decoding / Parsing - - char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - StaticJsonBuffer<200> jsonBuffer; +```c++ +char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - JsonObject& root = jsonBuffer.parseObject(json); +StaticJsonBuffer<200> jsonBuffer; - const char* sensor = root["sensor"]; - long time = root["time"]; - double latitude = root["data"][0]; - double longitude = root["data"][1]; +JsonObject& root = jsonBuffer.parseObject(json); + +const char* sensor = root["sensor"]; +long time = root["time"]; +double latitude = root["data"][0]; +double longitude = root["data"][1]; +``` [See complete guide](../Decoding-JSON) #### Encoding / Generating - - StaticJsonBuffer<200> jsonBuffer; - JsonObject& root = jsonBuffer.createObject(); - root["sensor"] = "gps"; - root["time"] = 1351824120; +```c++ +StaticJsonBuffer<200> jsonBuffer; - 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 +JsonObject& root = jsonBuffer.createObject(); +root["sensor"] = "gps"; +root["time"] = 1351824120; - root.printTo(Serial); - // This prints: - // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} +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]} +``` [See complete guide](../Encoding-JSON) \ No newline at end of file