arduino json 解析

#include 
void setup() {
 Serial.begin(9600);
 
 DynamicJsonDocument jsonBuffer(200);
 
 String json = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":
[48.756080,2.302038]}";
 deserializeJson(jsonBuffer, json);
 JsonObject root = jsonBuffer.as();
 
 const char* sensor = root["sensor"];
 long time = root["time"];
 double latitude = root["data"][0];
 double longitude = root["data"][1];
 Serial.println();
 Serial.println(sensor);
 Serial.println(time);
 Serial.println(latitude, 6);
 Serial.println(longitude, 6);
}
 
void loop() {
}

你可能感兴趣的:(智能硬件,c++)