V
V
Vladimir A2017-03-28 19:38:10
JSON
Vladimir A, 2017-03-28 19:38:10

How to create a string using the rapidjson library for example for a vector of strings?

There is 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 use the rapidjson library, before that I used it for "simple" variables (int, uint and others), the documentation unfortunately did not help me :(
P.C. the question is about what happens before addmember.
I would be sincerely grateful for the hint!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2017-03-28
@GavriKos

In JSON, a vector, an ordered list, an array of strings is represented like this:

[
"str1", "str2"
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question