Results 1 to 9 of 9

Thread: Qjson

  1. #1
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    37
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Qjson

    Hi,
    I am using the QJson for parsing. But I am stuck up with some issues. I have used the following code.

    void CityBook ::getCityList(QUrl url)
    {
    //!connect(cityReply, SIGNAL(readyRead()),this, SLOT(httpReadyRead()));
    cityGuideNetworkAccessManager = new QNetworkAccessManager(this);
    connect(cityGuideNetworkAccessManager, SIGNAL(finished(QNetworkReply*)),
    this, SLOT(httpReadyRead(QNetworkReply*)));
    QNetworkRequest cityRequest(url);
    cityGuideNetworkAccessManager->get(cityRequest);
    }

    void CityBook::httpReadyRead(QNetworkReply *reply)
    {
    QMessageBox::information(this, tr("HTTP"),
    tr(reply->readAll()),QMessageBox::NoButton
    );
    QJson::Parser parser;
    bool ok;
    const QByteArray &resultbyte = reply->readAll();
    qDebug() << resultbyte;
    QVariant result1 = parser.parse(reply->readAll(), &ok);
    qDebug() << result1;
    QVariantList result=parser.parse(resultbyte,&ok).toList();
    qDebug()<< result.size();
    if (!ok)
    {
    qFatal("An error occurred during parsing");
    exit (1);
    }
    qDebug() <<"error String"<< parser.errorString();
    qDebug() <<"error" //! QVariantList entries = result["name"].toList();
    foreach (QVariant city, result) {
    QVariantMap names = city.toMap();
    qDebug() << "\t-" << names.value("name");
    }
    }

    The output is

    Starting /Users/QT Developement/CityBook-build-desktop/CityBook.app/Contents/MacOS/CityBook...
    ""
    QVariant(, )
    0
    error String ""
    error 0

    Please help me .. Where I have done mistake… Thanks is advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qjson

    Qt Code:
    1. const QByteArray &resultbyte = reply->readAll();
    To copy to clipboard, switch view to plain text mode 
    What does this mean and do?

  3. #3
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    37
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Qjson

    The meaning of the QByteArray is to provide the array of the bytes. Here The reply->readAll returns the byte array.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qjson

    I know what a byte array is.

    I want to read from you what this line exactly does. I know what it does, but I want you to see the mistakes.

  5. #5
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    37
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Qjson

    Sorry. here i just assign the result to that particular variable.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qjson

    What happens if you use
    Qt Code:
    1. QByteArray resultbyte = reply->readAll();
    To copy to clipboard, switch view to plain text mode 
    ?

  7. The following user says thank you to tbscope for this useful post:

    Girija (17th September 2010)

  8. #7
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    37
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Qjson

    I am also getting the same output.

  9. #8
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    37
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Qjson

    Hi,

    I can see the parsing the result. Just I made one chance in the code based on the following link http://stackoverflow.com/questions/3...ng-some-issues.
    It is working fine.

    Thank u very much tbscope..

    Thanks a lot.

  10. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qjson

    Ohh, I didn't see the first readAll()

    Please use the code tags to format your code.

Similar Threads

  1. How to install Qjson in mac
    By Girija in forum Newbie
    Replies: 21
    Last Post: 17th September 2010, 09:55
  2. QJson Windows compile problem
    By skepticalgeek in forum Qt Programming
    Replies: 2
    Last Post: 9th August 2010, 01:15
  3. How to add a plugin? (QJson)
    By Thomas Wrobel in forum Newbie
    Replies: 5
    Last Post: 3rd December 2009, 21:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.