- 生成json数据
Json::Value root;
root["aaa"] = "aaaa";
root["bbb"] = "bbbb";
root["ccc"] = 3;
root["ddd"] = 4;
root["eeee"] = 5;
cout << StringJsonValue(root) << endl;
- 生成json数组
Json::Value array;
Json::Value root;
root["aaa"] = "aaaa";
root["bbb"] = 2;
array.append(root);
cout << StringJsonValue(array) << endl;
Json::Value array;
Json::Value root;
root["aaa"] = "aaaa";
root["bbb"] = 2;
array["list"].append(root);
cout << StringJsonValue(array) << endl;
- StringJsonValue
std::string StringJsonValue(Json::Value & root)
{
Json::StreamWriterBuilder write_builder;
return writeString(write_builder, root);
}