16,817
社区成员




{
"Customer": "{ “customerId”:”00001”,”customerName”:”gigglesun” }",
"ReturnCode": 200,
"Message": "login success"
}
void NetworkService::replyFinish(QNetworkReply *reply)
{
QString strJsonText = reply->readAll();
QString strText="";
QScriptValue jsontext;
QScriptEngine engineText;
jsontext = engineText.evaluate("value = " + strJsonText);
QScriptValueIterator iteratorText(jsontext);
while (iteratorText.hasNext())
{
iteratorText.next();
QScriptValue entry = iteratorText.value();
qDebug() << entry.toString();
if (iteratorText.name() == "ReturnCode")
{
m_returnCode = iteratorText.value().toInt32();
}
else if (iteratorText.name() == "Message")
{
strText = iteratorText.value().toString();
}
else if (iteratorText.name() == "Customer")
{
m_customId = iteratorText.value().toObject().property(0).toString();
}
}
}
"[object Object]"
"\u5904\u7406\u6210\u529F"
"200"
jsonObj["Customer"]..toObject()["CustomerId"]即可
QJsonDocument jsonResponse = QJsonDocument::fromJson(strJsonText.toUtf8());
QJsonObject jsonObj = jsonResponse.object();
qDebug()<<jsonObj["Customer"];
/*输出QJsonValue(object, QJsonObject({"CreatedById":0,"CreatedOn":"0001-01-01T00:00:00","C
ustomerId":"8e94d585-3c7b-45f3-9d12-f83acf886e3e","CustomerName":"gigglesun","Language":null,"Mobile":"15118123456","ModifiedById":0,"ModifiedOn":"0001-01-01T00:00:00","NickName":null,"Password":null,"SessionKey":"2a1eadf4-5ce4-4308-9530-15967a4baa91","UniqueId":"00000000-0000-0000-0000-000000000000"}))*/
QJsonArray customerInfoArray = jsonObj["Customer"].toArray();
qDebug() <<"size = "<< customerInfoArray.size(); // =0