我使用的是Qt5。我正在尝试从json对象获取值。下面是我试图从中获取数据的json对象的样子:
{
"success": true,
"properties": [
{
"ID": 1001,
"PropertyName": "McDonalds",
"key": "00112233445566778899aabbccddeeff"
},
{
"ID": 1002,
"PropertyName": "Burger King",
"key": "10112233445566778899aabbccddeeff"
},
{
"ID": 1003,
"PropertyName": "Taco Bell",
"key": "20112233445566778899aabbccddeeff"
}
]
}如何在Qt中创建包含properties[x].ID、properties[x].PropertyName和properties[x].key的三个数组?
编辑:
使用QScriptEngine时,我尝试了这样做:
QString data = (QString)reply->readAll();
QScriptEngine engine;
QScriptValue result = engine.evaluate(data);
qDebug() << result.toString();调试程序显示"SyntaxError: Parse error“
发布于 2022-01-06 13:25:45
我使用QT网络向Firebase发出API请求,但由于某种原因,我收到了一个充满数据的响应,但当解析到一个数组时,我收到了null。
void firebaseHandler::parseResponse(const QString &response){
@TODO for some reason sometimes the arrayData is empty
QJsonDocument jsonDocument = QJsonDocument::fromJson(response.toUtf8());
QJsonValue kind = jsonDocument.object().value("kind");
QJsonArray arrayData = jsonDocument.array();
qDebug() << "json response is " << jsonDocument.toJson();
}https://stackoverflow.com/questions/19822211
复制相似问题