繁体   English   中英

如何使用vector中的rapidjson库创建一个json文件<string>数据?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM