开发者

Parsing JSON using QJSON

开发者 https://www.devze.com 2023-01-15 21:42 出处:网络
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 outp

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

精彩评论

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