forked from bblanchon/ArduinoJson
39 lines
863 B
C++
39 lines
863 B
C++
// Copyright Benoit Blanchon 2014-2015
|
|
// MIT License
|
|
//
|
|
// Arduino JSON library
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
// delay(1000); <--needed for some boards (like Teensy)
|
|
|
|
StaticJsonBuffer<200> jsonBuffer;
|
|
|
|
char json[] =
|
|
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
|
|
|
JsonObject& root = jsonBuffer.parseObject(json);
|
|
|
|
if (!root.success()) {
|
|
Serial.println("parseObject() failed");
|
|
return;
|
|
}
|
|
|
|
const char* sensor = root["sensor"];
|
|
long time = root["time"];
|
|
double latitude = root["data"][0];
|
|
double longitude = root["data"][1];
|
|
|
|
Serial.println(sensor);
|
|
Serial.println(time);
|
|
Serial.println(latitude, 6);
|
|
Serial.println(longitude, 6);
|
|
}
|
|
|
|
void loop() {
|
|
// not used in this example
|
|
}
|