开发者

Parsing JSON using QJSON

M开发者_StackOverflow社区y json output look like [{"id":2,"name":"AAA"},{"id":1,"name":"BBB"}]. I want to parse this using Qjson in mac. I am trying to parsing but I could not get any outputs . please help me.

Thanks in advance.


I think that the issue is quite simple, the JSON representation implies an Array of records. You are trying to access the record without using an iterator or a loop.

Use the snippet below to transform the QVariant into a list

QVariantList result = parser.parse(cityReply->readAll(), &ok).toList();

And then loop against records for example:

foreach(QVariant record, result) {
    QVariantMap map = record.toMap();
    qDebug() << map.value("name");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜