【发布时间】:2017-03-28 18:48:47
【问题描述】:
我如何从以下位置创建 json 文件(字符串):
vector<string>m_paths
我有代码:
rapidjson::Document jsonfile;
jsonfile.SetObject();
rapidjson::Document::AllocatorType& jsonallocator = jsonfile.GetAllocator();
std::vector<String>::iterator itm;
rapidjson::Value paths(rapidjson::kArrayType);
for(itm = m_paths.begin(); itm != m_paths.end(); ++itm)
{
//rapidjson::Value jValueConverting;
// jValueConverting.SetString(GetLogRpl().c_str(), (rapidjson::SizeType)GetLogRpl().size(), jsonallocator);
}
jsonfile.AddMember("paths", paths, jsonallocator);
rapidjson::StringBuffer jsonstring;
rapidjson::Writer<rapidjson::StringBuffer> jsonwriter(jsonstring);
jsonfile.Accept(jsonwriter);
String fullJsonString = jsonstring.GetString();
return fullJsonString;
我必须使用 rapidjson 库,但不知道创建分配器后应该做什么。感谢您的帮助!
【问题讨论】:
-
请阅读stackoverflow.com/help/how-to-ask 并编辑您的问题以符合那里列出的标准。
-
我怀疑你需要担心分配器。如果你这样做了,rapidjson 的设计就很糟糕。分配器用于高级编程,您可能无法访问普通堆。
标签: c++ json string vector rapidjson