tags:

views:

72

answers:

1

Hi, My 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.

+1  A: 

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");
}
SleepyCod
I am getting the empty list. :(
Girija
Try this: QVariant result = parser.parse(cityReply->readAll(), qDebug() << result; Do you have any output in the console?
SleepyCod
I am getting the following output QVariant(, ).
Girija
I just made a test and it is outputting QVariant(QString, "AAA") QVariant(QString, "BBB")... I think the QJson lib is not correctly installed on your system.
SleepyCod
hi.. I got the paring data. just made one change in the code. using the link http://stackoverflow.com/questions/3732998/qjson-using-in-mac-getting-some-issues
Girija