Qt4第三方库QJSON编译说明



1. 下载QJSON源文件压缩包qjson-0.8.1.tar.bz2

2. Qt Create上使用cmake命令编译QJSON

(a) Qt Create中打开QJSON源文件中的CMakeLists.txt文件。

Qt4第三方库QJSON编译说明_第1张图片

(b) 弹出Run CMake设置界面,点击界面上的Run CMake检测通过,然后点击Finish按钮完成cmake环境配置。

Qt4第三方库QJSON编译说明_第2张图片

(c) 最后执行build命令编译源文件,会在lib目录下生成qjson.libqjson.dll文件,编译完成。

Qt4第三方库QJSON编译说明_第3张图片

 

3. 使用QJSON例程

#include 

#include 

#include 

#include "./src/parser.h"

 

int main(int argc, char *argv[])

{

          QCoreApplication app(argc, argv);

        QString json("{"

                "\"encoding\" : \"UTF-8\","

                "\"plug-ins\" : ["

                "\"python\","

                "\"c++\","

                "\"ruby\""

                "],"

                "\"indent\" : { \"length\" : 3, \"use_space\" : true }"

        "}");

 

      QJson::Parser parser;

       bool ok;

     QVariantMap result = parser.parse (json.toAscii(), &ok).toMap();

     if (!ok) {

          qFatal("An error occurred during parsing");

           exit (1);

      }

 

      qDebug() << "encoding:" << result["encoding"].toString();

      qDebug() << "plugins:";

      foreach (QVariant plugin, result["plug-ins"].toList()) {

            qDebug() << "\t-" << plugin.toString();

      }

      QVariantMap nestedMap = result["indent"].toMap();

      qDebug() << "length:" << nestedMap["length"].toInt();

      qDebug() << "use_space:" << nestedMap["use_space"].toBool();

      return app.exec();

}


你可能感兴趣的:(Qt)