Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: Creating a JSON array with objects

$
0
0
OK, I don't have a compiler with me right now, so this may be only approximate, but something like this:
json::value create_point(int x, int y)
{ 
    json::value result; 
    result[0] = x;   // or json::number(x);
    result[1] = y;   // or json::number(y);
    return result; 
}

json::value create_polygons()
{
    json::value first,second;
    first[U("id")] = "1";
    second[U("id")] = "2";

    json::value pol1;
    pol1[0] = create_point(10,20); pol1[1] = create_point(55,50);
    pol1[2] = create_point(55,56); pol1[3] = create_point(50,50);
    json::value pol2;
    pol2[0] = create_point(12,22); pol2[1] = create_point(55,52);
    pol2[2] = create_point(55,56); pol2[3] = create_point(51,52);

   first[U("poygon")] = pol1;
   second[U("poygon")] = pol2;

  json::value result;
  result[0] = first;
  result[1] = second;

  return result;
}
The U() macro is to make the string literals platform-independent: two-byte chars on Windows, single-byte chars on other platforms.

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>