mobizt / Firebase-ESP32

[DEPRECATED]🔥 Firebase RTDB Arduino Library for ESP32. The complete, fast, secured and reliable Firebase Arduino client library that supports CRUD (create, read, update, delete) and Stream operations.
MIT License
415 stars 118 forks source link

help:with accessing particular json path data. #36

Closed vamsikrishnaA9 closed 4 years ago

vamsikrishnaA9 commented 4 years ago

hi there, thanks for the library. i need to access the particular json key data. is there any way to access the particular key data with out using json.getiterator() function, because we need to put the particular array value to get the key and data. thank you

mobizt commented 4 years ago

Make sure you update library to the latest version. I recommended to download from git version.

You can use FirebaseJsonData to get the parse result like this.

Please refer to the doc here


//Declare FirebaseJsonData object to get the parse result, similar to FirebaseData object
FirebaseJsonData jsonData;

json.get(jsonData, "unit/temp2");

if (jsonData.success)
{
  //Print type of parsed data e.g string, int, double, bool, object, array, null and undefined
  Serial.println(jsonData.type);
  //Print its content e.g.string, int, double, bool whereas object, array and null also can access as string
  Serial.println(jsonData.stringValue);
  //Serial.println(jsonData.intValue);
  //Serial.println(jsonData.boolValue);
  //Serial.println(jsonData.doubleValue);
}

This makes it easy to get the content of complex and depth nested objects or array directly like this json.get(jsonData, "key1/key2/key3/[2]/[1]/[5]/key4/key5/[0]");

Where the number in [] is the index of array.

vamsikrishnaA9 commented 4 years ago

It works . Thank you