To parse an ArduinoJSON one simply needs to
String JSONpayload = "some JSON here";
StaticJsonDocument <512> geoLocationInfoJson;
DeserializationError error = deserializeJson(geoLocationInfoJson, JSONpayload);
if (error) {
this->mserial->printStrln("Error deserializing JSON");
}
To use the values within the StaticJsonDocument one first needs to
if ( geoLocationInfoJson.isNull() == true ){
String dataStr="NULL geoLocation data.\n";
Serial.print( dataStr);
return true;
}
next, is required to verify if a key exists. If TRUE, then is mandatory first to get the desired value into a corresponding data type, like below, and only afterward work on it, for instance, send it as a BLE message string:
if(this->interface->geoLocationInfoJson.containsKey("lat")){
float lat = this->interface->geoLocationInfoJson["lat"];
dataStr += "Latitude: "+ String(lat,4) + "\n";
}
if(this->interface->geoLocationInfoJson.containsKey("lon")){
float lon = this->interface->geoLocationInfoJson["lon"];
dataStr += "Longitude: "+ String(lon,4) + "\n";
}
if(this->interface->geoLocationInfoJson.containsKey("regionName"))
dataStr += String(this->interface->geoLocationInfoJson["regionName"].as<char*>()) + ", ";
The full code above is available on this GitHub repository:
https://github.com/aeonSolutions/aeonlabs-ESP32-C-Base-Firmware-Libraries
For more info have a look at these repositories on Github:
https://github.com/aeonSolutions/PCB-Prototyping-Catalogue
https://github.com/aeonSolutions/aeonlabs-open-software-catalogue