V
V
Vladimir A2017-03-29 15:39:49
JSON
Vladimir A, 2017-03-29 15:39:49

How to use json for string vector?

How to correctly implement the method for json (rapidjson library) for My work
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;

I don't know what to do after the allocator.. and before creating the buffer...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir A, 2017-03-29
@hauptling

maybe so

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);
        }
        return writer.EndArray();
        writer.EndObject();

        std::string fullJsonString = sb.GetString();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question