On 26.09.2013 14:00, Abhishek wrote:
> Hi All,
>
> Right now, I have seen examples of setting JSON key to set a value, for eg:
>
> my_object["name"]="Moshe";
> my_object["salary"]=1000.0;
>
> which creates json like:
> {name:"Moshe", salary:"1000.0"}
This is called an object.
> But what if I want to create a json string like:
>
> {"hello", "world", "value1", value2} ?
>
> I have these values in a std::vector<std::string>
>
> so, how should I create my_object to create json like --> {"hello", "world",
> "value1", value2}
what you mean is called array in json [0]
An array is something that is enclosed in squared brackets, like
[1,2,3,4]. This is possible. You just use the cppcms::json::array, which
is a typedef for std::vector<cppcms::json::value>. So it should work ;)
If you are using c++11 you can write this:
> #include <cppcms/json.h>
> cppcms::json::array a = {"string1", "string2", "string3"};
[0] http://en.wikipedia.org/wiki/Json#Data_types.2C_syntax_and_example
|