You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe a stupid question, but I cannot figure out from the API reference or the examples how to solve it.
I receive a JSON object with 2 JSON arrays:
{"msgkeys":["key1","key2","key3"],"msgs":["msg1",0.1234, 10]}
as jsonMsgs.
I can successfully parse the String to a JsonObject and to two JsonArrays with
// Convert message into JSON object
DynamicJsonBuffer jsonBuffer;
JsonObject& regJSON = jsonBuffer.parseObject(jsonMsgs);
if (regJSON.success()) {// Found some entries
if (regJSON.containsKey("msgkeys")) {
if (regJSON.containsKey("msgs")) {
JsonArray& msgKeysJSON = regJSON["msgkeys"];
JsonArray& msgsJSON = regJSON["msgs"];
if (msgKeysJSON.size() == msgsJSON.size()) {
for (int i=0; i<msgsJSON.size(); i++) {
messageIDs[i] = msgKeysJSON.get<String>(i);
// TODO get msgs and store in matching variable types
}
}
}
}
}
For the first array msgkeys, I know that all members are String, but for the second array msgs, the members can be anything allowed (boolean, float, double, signed char, .........) in a JSON array.
QUESTION:
How can I get the type of the entry for each member of the array msgsJSON????
I went down and up the API references and examples, but I could not find how to get information what type an entrance in the array is. I saw JsonVariant::is() in the API reference, but nothing how to use it or if it can be used on JsonArray.
The text was updated successfully, but these errors were encountered:
Also, I strongly encourage you to use iterators to read all values from a array:
for (JsonArray::iterator it=array.begin(); it!=array.end(); ++it) {
if (it->is<constchar*>()) {
Serial.print("It's a string");
}
if (it->is<int>()) {
Serial.print("It's an int");
}
}
Maybe a stupid question, but I cannot figure out from the API reference or the examples how to solve it.
I receive a JSON object with 2 JSON arrays:
{"msgkeys":["key1","key2","key3"],"msgs":["msg1",0.1234, 10]}
as jsonMsgs.
I can successfully parse the String to a JsonObject and to two JsonArrays with
For the first array msgkeys, I know that all members are String, but for the second array msgs, the members can be anything allowed (boolean, float, double, signed char, .........) in a JSON array.
QUESTION:
How can I get the type of the entry for each member of the array msgsJSON????
I went down and up the API references and examples, but I could not find how to get information what type an entrance in the array is. I saw JsonVariant::is() in the API reference, but nothing how to use it or if it can be used on JsonArray.
The text was updated successfully, but these errors were encountered: