我想在 symbian 应用程序中解析这个 JSON 输出:
[
{"ID":"9","titel":"wouter","plaatsID":"2616","prio":"3"},
{"ID":"8","titel":"pasta","plaatsID":"3780","prio":"3"},
{"ID":"6","titel":"Muts prikken","plaatsID":"3780","prio":"2"
{"ID":"5","titel":"doorplannen","plaatsID":"3840","prio":"2"}
{"ID":"4","titel":"Gasfles","plaatsID":"3780","prio":"2"}
]
为此,我编写了以下代码,但我无法读取数据。其他单个 JSON 输出它工作正常,但多个输出不起作用:
void start::finishedSlot(QNetworkReply * reply)
{
// Reading attributes of the reply
// e.g. the HTTP status code
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
// see CS001432 on how to handle this
// no error received?
if (reply->error() == QNetworkReply::NoError)
{
QByteArray data = reply->readAll();
bool ok;
QVariantMap result = Json::parse(QString(data), ok).toMap();
if(!ok) {
qFatal("An error occurred during parsing");
exit(1);
}
QMapIterator<QString, int> i(result);
while (i.hasNext()) {
i.next();
cout << i.key() << ": " << i.value() << endl;
}
ui->log->setText("het gaat goed");
}
// Some http error received
else
{
ui->log->setText("gaat NIET goed");
}
delete reply;
}