tags:

views:

44

answers:

1

Hi,

How to install the Qjson in mac?

Thanks in advance.

+1  A: 

Refer to the "get it" tab on the QJson website. MacOs X is a Unix system

Edit for parsing:

Try this for your Json string "[{"id":2,"name":"AAA"},{"id":1,"name":"BBB"}]"

QJson::Parser parser;
bool ok;
QVariantMap result=parser.parse (cityReply->readAll(),&ok).toMap();
if (!ok)
{
    qFatal("An error occurred during parsing");
    exit (1);
}

foreach (QVariant city, result.toList())
{
    QVariantMap names = city.toMap();
    qDebug() << "\t-" << names["name"].toString();
}

Please open a new Question if you have an other question.

Patrice Bernassola
Thanks. But it shows the error : "You are building a 64-bit application, but using a 32-bit version of Qt. Check your build configuration." please help me.
Girija
Regarding the error, you need to specify you are building a 32-bit application. Check the build configuration and force 32-bit if necessary
Patrice Bernassola
Thank u very much Patrice. But, 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.
Girija
Have you some errors? Regarding your Json chain it's an array with 2 objects in it. Format seems to be ok
Patrice Bernassola
I am using the following code, QJson::Parser parser; bool ok; QVariantMap result=parser.parse (cityReply->readAll(), if (!ok) { qFatal("An error occurred during parsing"); exit (1); } qDebug() << "Name :" << result.value("name").toString(); } the output is : Name : "" Note : if I displays cityReply->readAll() in messagebox then I can view the webservice result (json String).
Girija
You are getting an array in result. You need to convert it to list to use it and then get the name in each object. See the edit in my answer
Patrice Bernassola
Thanks Patrice.
Girija
Hi Patrice, Still I am getting errors like "could not convert QVariantMap to QList". :( I posted as a new question. Please help me. Thanks in advance.
Girija