2014-03-01 12:59:45 +01:00
|
|
|
/*
|
2014-07-05 13:09:46 +02:00
|
|
|
* Arduino JSON library - Parser Example
|
2014-03-01 12:59:45 +01:00
|
|
|
* Benoit Blanchon 2014 - MIT License
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <JsonParser.h>
|
|
|
|
|
2014-07-03 14:00:51 +02:00
|
|
|
using namespace ArduinoJson::Parser;
|
|
|
|
|
2014-07-05 13:09:46 +02:00
|
|
|
void setup()
|
2014-03-01 12:59:45 +01:00
|
|
|
{
|
2014-07-05 13:09:46 +02:00
|
|
|
Serial.begin(9600);
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-07-17 13:23:18 +02:00
|
|
|
char json [] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-07-05 13:09:46 +02:00
|
|
|
JsonParser<16> parser;
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-07-17 14:02:51 +02:00
|
|
|
JsonHashTable root = parser.parse(json);
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-07-05 13:09:46 +02:00
|
|
|
if (!root.success())
|
2014-03-01 12:59:45 +01:00
|
|
|
{
|
2014-07-17 13:23:18 +02:00
|
|
|
Serial.println("JsonParser.parse() failed");
|
2014-03-01 12:59:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-17 14:02:51 +02:00
|
|
|
char* sensor = root["sensor"];
|
|
|
|
long time = root["time"];
|
|
|
|
double latitude = root["data"][0];
|
2014-07-17 13:23:18 +02:00
|
|
|
double longitude = root["data"][1];
|
2014-03-01 12:59:45 +01:00
|
|
|
|
2014-07-17 13:23:18 +02:00
|
|
|
Serial.println(sensor);
|
2014-07-05 13:09:46 +02:00
|
|
|
Serial.println(time);
|
2014-07-17 13:23:18 +02:00
|
|
|
Serial.println(latitude, 6);
|
|
|
|
Serial.println(longitude, 6);
|
2014-03-01 12:59:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
|
2014-07-05 13:09:46 +02:00
|
|
|
}
|