一、环境搭建:
参考文章:https://blog.csdn.net/fakine/article/details/79272090
二、创建实例:
#include <stdio.h> #include <direct.h> #include <io.h> #include <sys/stat.h> #include <string> #include <json.h> #include <iostream> #include <fstream> using namespace std; void MyMethod::creatJsonFile(void) { //根节点 Json::Value root; //根节点属性1 root["value1"] = "value_1"; root["root1"]["value_1_1"] = Json::Value("value_1_1"); root["array"].append("member1"); root["array"].append("member2"); root["array"].append("member3"); cout << "StyledWriter:" << endl; Json::StyledWriter sw; cout << sw.write(root) << endl; } 调用:MyMethod::creatJsonFile();
生成结果如下: StyledWriter: { "array" : [ "member1", "member2", "member3" ], "root1" : { "value_1_1" : "value_1_1" }, "value1" : "value_1" }
原文地址:https://www.cnblogs.com/xian-yongchao/p/10241732.html
时间: 2024-10-11 13:55:33