I have a QByteArray containing the following JSON:
{ "response": { "count": 2, "items": [ {"name": "somename", "key": 1"}, {"name": "somename", "key": 1"} ] } }
You need to parse and get the necessary data:
QJsonDocument itemDoc = QJsonDocument::fromJson(answer); QJsonObject itemObject = itemDoc.object(); qDebug() << itemObject; QJsonArray itemArray = itemObject["response"].toArray(); qDebug() << itemArray;
The first debug displays the content of the entire QByteArray
recorded in itemObject
, the second debug displays nothing.
Tell me, maybe you need to parse differently, or why this method does not work?