bblanchon / ArduinoJson

📟 JSON library for Arduino and embedded C++. Simple and efficient.
https://arduinojson.org
MIT License
6.63k stars 1.1k forks source link

I want de-frame a sentence in Arduino #712

Closed navinyate closed 6 years ago

navinyate commented 6 years ago

Am using Neoway N10 GPRS module, where I using the location of a device.

The Sentence is +CIPGSMLOC: {"location":{"lat":12.534121,"lng":76.9126},"accuracy":550.0}

Am trying to get lat and lon and use this as variable.

Please help me.

bblanchon commented 6 years ago
const size_t bufferSize = 2*JSON_OBJECT_SIZE(2) + 60;
DynamicJsonBuffer jsonBuffer(bufferSize);

const char* json = "{\"location\":{\"lat\":12.534121,\"lng\":76.9126},\"accuracy\":550}";

JsonObject& root = jsonBuffer.parseObject(json);

float location_lat = root["location"]["lat"]; // 12.534121
float location_lng = root["location"]["lng"]; // 76.9126

int accuracy = root["accuracy"]; // 550
bblanchon commented 6 years ago

How to use ArduinoJson

navinyate commented 6 years ago

@bblanchon love it