dropbox / json11

A tiny JSON library for C++11.
MIT License
2.55k stars 613 forks source link

String Vector to Json::array #63

Closed hassanfarid closed 8 years ago

hassanfarid commented 8 years ago

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 8 years ago

Iterate through the vector and use Json::parse on each string, build up a vector<Json>, then convert the result to Json

hassanfarid commented 8 years ago

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 6 years ago

I forgot the solution that I found earlier, and found it useful finding it here. Thanks myself. :)