String Vector to Json::array
hassanfarid opened this issue · 3 comments
hassanfarid commented
I have std::vectorstd::string
each string value is json object = "{"key":"value"}"
How can make a Json::object of value
"[{"key":"value"}, {"key":"value"}]"
j4cbo commented
Iterate through the vector and use Json::parse
on each string, build up a vector<Json>
, then convert the result to Json
hassanfarid commented
I found a solution myself:
Use Json::array constructor,
Json j = Json::array({vector_of_string_with_json_formatted_string});
cout<<j.dump();
this would result in string:
"[[{"key":"value"}, {"key":"value"}]]"
so then you can use below code to get required object format,
cout<<j[0].dump();
hassanfarid commented
I forgot the solution that I found earlier, and found it useful finding it here. Thanks myself. :)