zoukankan      html  css  js  c++  java
  • Qt QJson解析json数据

    Qt QJson解析json数据

    //加载根目录文件

    void TeslaManageData::loadRootFolderFiles()
    {
        QNetworkAccessManager *manager = new QNetworkAccessManager(this);;
        QNetworkRequest network_request;
        QByteArray post_data;
    
        network_request.setUrl(QUrl("http://121.60.49.57:9080/tsinghuaVCService/init/selectAllFolder.action"));
        network_request.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36");
    
        connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
    
        //发送请求
        manager->get(network_request);
    }
    void TeslaManageData::replyFinished(QNetworkReply* networkReply)
    {
        QTextCodec *codec = QTextCodec::codecForName("utf8");
        QByteArray allData = networkReply->readAll();
        //使用utf8编码,这样才可以显示中文  
        QString all = codec->toUnicode(allData);
        
        QJsonParseError jsonError;
        QJsonDocument doucment = QJsonDocument::fromJson(allData, &jsonError);  // 转化为 JSON 文档
        if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) {  // 解析未发生错误
            QJsonArray jsonArray1 = doucment.array();
            
            QJsonArray::Iterator iter1;
            for (iter1 = jsonArray1.begin();iter1 != jsonArray1.end();++iter1)
            {
                QJsonObject jsonObject1 = (*iter1).toObject();
                parseJsonObjectI(jsonObject1);
            }
        }
        networkReply->deleteLater();   
    }
  • 相关阅读:
    HTML5
    PHP
    eclipse项目导入到android studio
    Jpush教材
    Android性能优化典范
    Fresco好案例
    扫二维码关注微信号,回复“送礼包”就送超值大礼!
    Android开源项目大全之工具库
    android学习“知乎”建议
    C# Json时间类型的转换
  • 原文地址:https://www.cnblogs.com/herd/p/11877520.html
Copyright © 2011-2022 走看看