{
"physicaldrives":
[
{
"data":
{
"dev_id": "0",
"ssd_life_left": "0"
}
},
{
"data":
{
"dev_id": "1",
"ssd_life_left": "10"
}
}
]
}
{
"physicaldrives":
[
{
"data":
{
"dev_id": "0",
"ssd_life_left": "0"
}
},
{
"data":
{
"dev_id": "1",
"ssd_life_left": "10"
}
}
]
}
To copy to clipboard, switch view to plain text mode
this is snippet of JSON how can I parse it in Qt 5
i have tried this
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
if(jsonResponse.isEmpty())
return false;
QJsonObject jsonObj = jsonResponse.object();
QJsonArray jsonArray = jsonObj["physicaldrives"].toArray();
if(jsonArray.isEmpty())
return false;
qDebug()<< "jsonArray phyDatas" << jsonArray ;
// fatching JSONArray of Ph
foreach (const QJsonValue & value, jsonArray)
{
QJsonObject obj = value.toObject();
phydata.append(obj["data"].toString());
qDebug()<< "phyDatas" << phydata ;
}
// fatching value from JSONArray
QJsonValue val = obj["dev_id"];
qDebug()<< "devID" << val.toInt(); ;
QString strReply = (QString)reply->readAll();
QStringList phydata;
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
if(jsonResponse.isEmpty())
return false;
QJsonObject jsonObj = jsonResponse.object();
QJsonArray jsonArray = jsonObj["physicaldrives"].toArray();
if(jsonArray.isEmpty())
return false;
qDebug()<< "jsonArray phyDatas" << jsonArray ;
// fatching JSONArray of Ph
foreach (const QJsonValue & value, jsonArray)
{
QJsonObject obj = value.toObject();
phydata.append(obj["data"].toString());
qDebug()<< "phyDatas" << phydata ;
}
// fatching value from JSONArray
QJsonValue val = obj["dev_id"];
qDebug()<< "devID" << val.toInt(); ;
To copy to clipboard, switch view to plain text mode
but I dont know its right way or not?
how can I get list of "drv_id" of "data" object ??????
Bookmarks