Files
ArduinoJson/examples/JsonParserExample/JsonParserExample.ino

44 lines
832 B
Arduino
Raw Normal View History

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-05 13:09:46 +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-05 13:09:46 +02:00
JsonHashTable root = parser.parseHashTable(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
{
Serial.println("JsonParser.parseHashTable() failed");
return;
}
2014-07-16 21:10:18 +02:00
char* sensor = root["sensor"];
2014-07-05 13:09:46 +02:00
Serial.println(sensor);
2014-03-01 12:59:45 +01:00
2014-07-16 21:10:18 +02:00
long time = root["time"];
2014-07-05 13:09:46 +02:00
Serial.println(time);
2014-07-16 21:10:18 +02:00
JsonArray coords = root["data"];
2014-07-05 13:09:46 +02:00
2014-07-16 21:10:18 +02:00
for (int i = 0; i < coords.size(); i++)
2014-03-01 12:59:45 +01:00
{
2014-07-16 21:10:18 +02:00
double value = coords[i];
2014-07-05 13:09:46 +02:00
Serial.println(value, 6);
2014-03-01 12:59:45 +01:00
}
}
void loop()
{
2014-07-05 13:09:46 +02:00
}