How to create a JSON object from two vectors in c++? -


i'm new json,c++ , c++ rest sdk i'm struggling creating json object 2 vectors right now. have right now: 2 vectors containing dimension data

 std::vector<glm::vec3> bookdimension{     glm::vec3(x1,       y1,   z1),  // element in vector float type     glm::vec3(x2,       y2,   z2),  // element in vector float type     glm::vec3(x3,       y3,   z3),  // element in vector float type }; std::vector<glm::vec3> containerdimension{     glm::vec3(x4,       y4,   z4), // element in vector float type }; 

i want use these 2 vectors , create single json object, structure of json object

{"b":[      [x1,y1,z1],[x2,y2,z2],[x3,y3,z3]      ],  "c":[[x4,y4,z4]      ]  } 

i'm not sure how initialize correct obj. below can reach far

json::value jsonobj; std::vector<glm::vec3>::const_iterator = bookdimension.begin(), end = boxdimension.end(); (; != end; ++it) {     (jsonobj["b"][it][0]) = it->x;     jsonobj["b"][it][1] = it->y;     jsonobj["b"][it][2] = it->z; } 

and error web::json::value::operator[](const std::string &key) (declared @ line xxxx of "..\json.h") in accessible

appreciate help/hints in advance! thank much!

based on code "the wiki" i'm guessing you're using microsoft's c++ rest sdk. if that's case, should work like

json::value finalobject; json::value bookdimjsonarray; for(unsigned int i=0;i<bookdimension.size();i++){     json::value vec3array;     vec3array[0]=bookdimension[i].x;     vec3array[1]=bookdimension[i].y;     vec3array[2]=bookdimension[i].z;     bookdimjsonarray[i]=vec3array; } json::value containerdimjsonarray; for(unsigned int i=0;i<containerdimension.size();i++){     json::value vec3array;     vec3array[0]=containerdimension[i].x;     vec3array[1]=containerdimension[i].y;     vec3array[2]=containerdimension[i].z;     containerdimjsonarray[i]=vec3array; } finalobject[l"b"]=bookdimjsonarray; finalobject[l"c"]=containerdimjsonarray; 

although might want use object vec3 representation since number of elements wont change (vec3obj[l"x"]=bookorcontainerdimension[i].x etc.)

i'm pretty sure on guess because l"string" syntax microsoft extension, next time please post library you're using, preferably in both question , tag.

incase i'm wrong, add string yourself, using string , +=


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -