开发者

QJSON using in Mac - getting some issues

开发者 https://www.devze.com 2023-01-17 00:28 出处:网络
I am using the QJson for parsing. But I am stuck up with some issues. I have used the following code:

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" <parser.errorLine();  
    //! QVariantList entries = result["name"].toList();  
    foreach (QVariant ci开发者_JAVA技巧ty, 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  


The result of the readAll function is an empty byte array. According to documentation this can mean either that no data are available or that an error occurred.

0

精彩评论

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

关注公众号