如何制作 jsoncpp 数组?

JJ *_*nes 4 c++ arrays json jsoncpp

我被jsoncpp困住了。我想创建一个像这样的数组:

"Cords": [{"x": 10, "y": 20}, {"x": 70, "y": 40}, {"x": 15, "y": 65}]
Run Code Online (Sandbox Code Playgroud)

我设法用 jsoncpp 做常规的事情(见下文),但我陷入了制作 JSON 数组的情况。

Json::Value event;

event["name"] = "Joe";
event["Direction"]["left"]["x"] = "1338";
event["Direction"]["right"]["x"] = "1337";
Run Code Online (Sandbox Code Playgroud)

编辑:
我想在事件中打印所有内容。
我不想单独打印电线。

Cal*_*eth 5

您需要使用int重载operator[]来定义数组

Json::Value coord(int x, int y)
{
    Json::Value result;
    result["x"] = x;
    result["y"] = y;
    return result;    
}

void make_event(Json::Value & event)
{
    Json::Value & coords = event["Cords"];
    coords[0] = coord(10, 20);
    coords[1] = coord(70, 40);
    coords[2] = coord(15, 65);
}
Run Code Online (Sandbox Code Playgroud)