Reputation: 43
How can i create json file (string) from:
vector<string>m_paths
I have code:
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;
I must use rapidjson library and don't know what i should do after creating allocator. Thanks for any help!
Upvotes: 0
Views: 2815
Reputation: 621
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();
Upvotes: 1