- json11的github地址
https://github.com/dropbox/json11
- 代码
#include <iostream>
#include "json11.hpp"
using namespace std;
int main()
{
    // JSON对象
    json11::Json::object root;
    root["ChanCode"] = "1";
    root["ChanDesc"] = nullptr;
    root["ChanType"] = "5";
    // JSON数组
    json11::Json::array subArray;
    json11::Json::object subObj1;
    subObj1["IP"] = "127.0.0.1";
    subObj1["Port"] = "10086";
    json11::Json::object subObj2;
    subObj2["IP"] = "127.0.0.1";
    subObj2["Port"] = "10010";
    // JSON数组添加元素
    subArray.push_back(subObj1);
    subArray.push_back(subObj2);
    root["Address"] = subArray;
    json11::Json json = root;
    std::string strJson = json.dump();
    cout << strJson << endl;
    cout << strJson.length() << endl;
    return 0;
}
- JSON数据
{"Address": [{"IP": "127.0.0.1", "Port": "10086"}, {"IP": "127.0.0.1", "Port": "10010"}], "ChanCode": "1", "ChanDesc": null, "ChanType": "5"}










