ubuntu下使用jsoncpp例子

前端之家收集整理的这篇文章主要介绍了ubuntu下使用jsoncpp例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ubunt下安装参考

http://www.360doc.com/content/14/0725/08/14679766_396880822.shtml


编写测试

  • main.cpp
  • @H_404_11@
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <iostream>
    
    #include "json/json.h" 
    
    @H_502_23@using @H_502_23@namespace std;
    
    @H_502_23@int main()
    {
        string test ="{\"id\":1,\"name\":\"kurama\"}";
        Json::Reader reader;
        Json::Value value;
        @H_502_23@if(reader.parse(test,value))
        {
          @H_502_23@if(!value["id"].isNull())
          {
            cout<<value["id"].asInt()<<endl;
            cout<<value["name"].asString()<<endl;
          }
        }
    
        @H_502_23@return 0;
    }
    • CMakeLists.txt
    • @H_404_11@
      @H_502_23@PROJECT (FUN)
      
      @H_502_23@set(APP_SRC main.cpp)
      @H_502_23@set(exe_name test)
      @H_502_23@set(lib_name json_linux-gcc-5.4.0_libmt)
      
      # 库头文件所在目录
      @H_502_23@set(lib_inc /home/ding/Downloads/jsoncpp-src-0.5.0/@H_502_23@include CACHE PATH "include of ")
      # 库文件所在目录
      @H_502_23@set(lib_dir /home/ding/Downloads/jsoncpp-src-0.5.0/libs/linux-gcc-5.4.0 CACHE PATH "directory of .lib")
      
      # 在这里动态库与静态库的设置是一样的
      # 指定头文件搜索路径
      @H_502_23@include_directories(${lib_inc})
      # 指定库文件搜索路径
      @H_502_23@link_directories(${lib_dir})
      
      # 可执行文件生成在 ./bin下面
      @H_502_23@set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
      
      # 生成可执行文件
      @H_502_23@add_executable(${exe_name} ${APP_SRC})
      
      # 可执行文件 需要链接
      @H_502_23@target_link_libraries(${exe_name} ${lib_name})
      • 运行脚本travis.sh
      • @H_404_11@
        #!/usr/bin/env sh
        #set -evx
        #env | sort
        
        EXE_DIR=./bin
        BUILD_DIR=./build
        
        @H_502_23@if [ ! -d ${EXE_DIR} ] 
        @H_502_23@then
            mkdir ${EXE_DIR}
        @H_502_23@else
        #echo "aaa"
            rm -rf ${EXE_DIR}/* 
        @H_502_23@fi
        
        @H_502_23@if [ ! -d ${BUILD_DIR} ]
        @H_502_23@then 
            mkdir ${BUILD_DIR} 
        @H_502_23@else
        #echo "ccc"
            rm -rf ${BUILD_DIR}/*
        @H_502_23@fi
        
        cd build
        cmake ..
        make

        cmake 参考
        https://github.com/doctording/cmake_study

        执行运行

        $./travis.sh

猜你在找的Ubuntu相关文章