Parsing/ Deserializing JSON #327
Unanswered
garymansted
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You also can cast the Json object from the FirebaseData like this FirebaseJson json = fbObject.to<FirebaseJson>(); To deserialize // parse with known key
json.get(result, "-N0nOiQW93Qwmrak4Zo4");
if (result.success)
{
if (result.typeNum == FirebaseJson::JSON_STRING)
{
Serial.println(result.stringValue);
}
else if (result.typeNum == FirebaseJson::JSON_INT)
{
Serial.println(result.intValue);
}
}
// or iterate all elements
size_t len = json.iteratorBegin();
FirebaseJson::IteratorValue value;
for (size_t i = 0; i < len; i++)
{
value = json.valueAt(i);
Serial.printf((const char *)FPSTR("%d, Name: %s, Value: %s\n"), i, value.key.c_str(), value.value.c_str());
}
json.iteratorEnd();
You can see how to handle FirebaseData from the RTDBHelper.h which included in all RTDB examples. Firebase-ESP8266/src/addons/RTDBHelper.h Lines 24 to 130 in 1373b01 The FirebaseJson examples are available in examples folder too. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I was wondering if you could give me a tip at what id need to do to deserialize the following JSON.
Im trying to access the values but am having trouble. I read through the docs and the went through the examples but still having trouble understanding what I'd need to do. Any help greatly appreicated! BTW awesome library!
Beta Was this translation helpful? Give feedback.
All reactions