zoukankan      html  css  js  c++  java
  • C++之jsoncpp学习

    最新由于客户端要用到jsoncpp,所以自己也跟着项目的需求学了一下jsoncpp.以前没用过xml,但是感觉接触json后,还蛮好用的。

    参考地址 http://jsoncpp.sourceforge.net/class_json_1_1_value.html

    #include <QtCore/QCoreApplication>

    #include <json/json.h>

    #include <string>

    using std::string;

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

    {

       Json::Reader reader;      

       Json::Value json_object;

        const char* json_document = "{/"age/" : 26,/"person/":[{/"id/":1,/"study/":[{/"language/":/"chinese/"}],/"name/":/"chen/"},{/"id/":2,/"name/":/"zhang/"}],/"name/" : /"huchao/"}";

        if (!reader.parse(json_document, json_object))//读入字符串,然后转换成json格式

        return 0;

       int a1=0;

        json_object["name"] ="wang";//修改数据

       json_object["person"][a1]["study"][a1]["language"] = "English";

        std::cout << json_object["name"] << std::endl;//读取数据

        std::cout << json_object["person"][a1]["study"][a1]["language"]<< std::endl;

        std::cout << json_object["age"] << std::endl;

        Json::Value json_object;

        json_object.append("11");   //加入数组格式

        json_object.append("12");

        json_object.append("13");

        return a.exec();

    }

    要下载jsoncpp,然后程序包含jsoncpp源码。

  • 相关阅读:
    HDNOIP201404最短路径
    BJOI2015 Day3
    BJOI2015 Day2
    BJOI2015 Day1
    BZOJ4012 [HNOI2015]开店
    hdu2159(二维完全背包)
    hdu3496(二维背包)
    hdu3033(变形分组背包)
    hdu1267(递推)
    hdu1503(最长公共子序列)
  • 原文地址:https://www.cnblogs.com/MingZznet/p/3228159.html
Copyright © 2011-2022 走看看