更新时间:2023-11-09 23:48:10
有2种机制.如果您习惯于使用std c ++库,则应该看起来很熟悉.元素向量是从std :: vector派生的.
There are 2 mechanisms. If you are used to std c++ libraries, this should look familiar. Element vector is derived from std::vector.
json::value::element_vector e;
// the first item in the pair is the array index, the second the value
e.push_back(std::make_pair(json::value(0), json::value(false)));
e.push_back(std::make_pair(json::value(1), json::value::string(U("hello"))));
json::value arr(e);
而且,如果您希望外观更整洁,并且可以接受效率较低的编译结果:
And, if you prefer a cleaner look, and can accept a less efficient compiled result:
json::value arr;
arr[0] = json::value(false);
arr[1] = json::value(U("hello"));
从您的信息中您尝试了很多东西.如果您尝试过类似的机制,但它们无法正常工作,请给我们提供一个示例程序,以消除故障,然后再进行破解.
From your message you have tried a bunch of stuff. If you have tried mechanisms like these but they didn't work, give us a sample program that demontrates the failure and we'll have a crack at it.
要在上面的文件中获取基本结构:
To get the basic structure in your file above:
json::value vehicles;
vehicles[0] = // 1st vehicle object
vehicles[1] = // 2nd vehicle object
// etc
json::value root;
root[L"timestep"] = json::number(2160.0);
root[L"vehicles"] = vehicles;