我有QByteArray,包含此JSON
{"response":
{"count":2,
"items":[
{"name":"somename","key":1"},
{"name":"somename","key":1"}
]}}
Run Code Online (Sandbox Code Playgroud)
需要解析并获取所需的数据:
QJsonDocument itemDoc = QJsonDocument::fromJson(answer);
QJsonObject itemObject = itemDoc.object();
qDebug()<<itemObject;
QJsonArray itemArray = itemObject["response"].toArray();
qDebug()<<itemArray;
Run Code Online (Sandbox Code Playgroud)
第一次调试显示记录在itemObject中的所有QByteArray的内容,第二次调试不显示任何内容。
我是否必须对此进行解析,否则为什么此方法无效?
我有一个QUrl这样的:
https://www.example.com/index.html#token=SomeToken&user=guest
我想获取令牌的值 ie SomeToken。我知道方法QUrl::queryItemValue,所以这段代码必须有效:
void MainWindow::get_token(QUrl url)
{
url = url.toString().replace("?","#");
QString token = url.queryItemValue("token");
}
Run Code Online (Sandbox Code Playgroud)
但是Qt5我不能使用这个方法,我该如何解析url?