Updated example

This commit is contained in:
Benoît Blanchon
2014-07-17 13:23:18 +02:00
parent 45c9ba1191
commit 78249a0ada
2 changed files with 14 additions and 19 deletions

View File

@ -1,13 +1,12 @@
/* /*
* malloc-free JSON parser for Arduino * Arduino JSON library
* Benoit Blanchon 2014 - MIT License * Benoit Blanchon 2014 - MIT License
*/ */
// This file is here to help the Arduino IDE find the .cpp files // This file is here to help the Arduino IDE find the .cpp files
#include "JsonParser/JsonArray.cpp" #include "JsonParser/JsonArray.cpp"
#include "JsonParser/JsonHashTable.cpp" #include "JsonParser/JsonHashTable.cpp"
#include "JsonParser/JsonObjectBase.cpp"
#include "JsonParser/JsonParserBase.cpp" #include "JsonParser/JsonParserBase.cpp"
#include "JsonParser/JsonValue.cpp" #include "JsonParser/JsonValue.cpp"
#include "JsonParser/jsmn.cpp" #include "JsonParser/jsmn.cpp"

View File

@ -11,31 +11,27 @@ void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; char json [] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
JsonParser<16> parser; JsonParser<16> parser;
JsonHashTable root = parser.parseHashTable(json); JsonValue root = parser.parse(json);
if (!root.success()) if (!root.success())
{ {
Serial.println("JsonParser.parseHashTable() failed"); Serial.println("JsonParser.parse() failed");
return; return;
} }
char* sensor = root["sensor"]; char* sensor = root["sensor"];
long time = root["time"];
double latitude = root["data"][0];
double longitude = root["data"][1];
Serial.println(sensor); Serial.println(sensor);
long time = root["time"];
Serial.println(time); Serial.println(time);
Serial.println(latitude, 6);
JsonArray coords = root["data"]; Serial.println(longitude, 6);
for (int i = 0; i < coords.size(); i++)
{
double value = coords[i];
Serial.println(value, 6);
}
} }
void loop() void loop()