Creating JSON arrays

Oct 14, 2015 at 4:14 PM
I looked at the JSON page provided, but I am still not sure how you create a JSON object and send it back, more spefically a JSON array, such as
    { "Title": "DSU" },
    { "Title": "USD" }
I suppose I could do something like this using a format string (as DSU, USD would be dynamic data)
json::value seasons = json::value::parse(U("[{\"Title\": \"DSU\"},{\"Title\": \"USD\"}]"));
however I much rather do something like
json::value seasons = json::value::array();

for(int i = <0; i < data.count; i++)
     seasons[i]["Title"] = json::foo(data[i]);
Could anyone provide a basic example? Thanks
Oct 14, 2015 at 6:57 PM
hey ntgates

Yes, we completely support what you are looking for :)
You can use json::value::string() to construct a json string and assign it as json object values, something like:
    json::value seasons = json::value::array();
    for (int i = 0; i < data.size(); i++)
        seasons[i][U("Title")] = json::value::string(data[i]);
I would browse through our tests to get a better understanding of how to use the JSON APIs, for instance: JSON construction test has examples on how to construct JSON arrays, objects, strings. (Please note, we are moving to github, hence the reference from github).