I have QByteArray,contains this JSON
{"response":
{"count":2,
"items":[
{"name":"somename","key":1"},
{"name":"somename","key":1"}
]}}
Need to parse and get the required data:
QJsonDocument itemDoc = QJsonDocument::fromJson(answer);
QJsonObject itemObject = itemDoc.object();
qDebug()<<itemObject;
QJsonArray itemArray = itemObject["response"].toArray();
qDebug()<<itemArray;
First debug displays the contents of all QByteArray, recorded in itemObject, second debug does not display anything.
Must i parse this otherwise,or why this method does not work?
I'm not familiar with qt APIs in particular, but in general JSON objects cannot be coerced into arrays unless they are JSON arrays (ex: the value for "items").
Perhaps you want something like: