![](/img/trans.png)
[英]How to get the values from json format string using rapidjson library in C++
[英]How to create a json file using the rapidjson library from vector<string> data?
我如何從以下位置創建 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 庫,但不知道創建分配器后應該做什么。 謝謝你的幫助!
StringBuffer sb;
PrettyWriter writer(sb);
writer.StartObject();
writer.String(_T("paths"));
writer.StartArray();
std::vector<String>::iterator itm;
for(itm = m_paths.begin(); itm != m_paths.end(); ++itm)
{
writer.String(*itm);
}
writer.EndArray();
writer.EndObject();
std::string fullJsonString = sb.GetString();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.