如何从rapidjson获取重复键的值?

时间:2014-12-17 09:06:20

标签: c++ json rapidjson

我是rapidjson的新手,我的文字低于json

{"Response":"GetAllocations","ResponseCode":200,"ports":[0,1,2],"ports":[3,4,5], "ports":[6,7,8]}

如何按键0, 1, 2; 3, 4, 5; 6, 7, 8提取值"ports"

提前致谢。

1 个答案:

答案 0 :(得分:0)

啊,我的代码如下:

rapidjson::Document doc;
if (doc.Parse(sssss.c_str()).HasParseError() || !doc.IsObject() || !doc.HasMember("Response") || !doc["Response"].IsString())
{
    return 0;
}

for (SizeType i = 0; i < doc["ports"].Size(); ++i)
{
    cout << "id = " << doc["ports"][0].GetUint() << endl;
    cout << "port1 = " << doc["ports"][1].GetUint() << endl;
    cout << "port2 = " << doc["ports"][2].GetUint() << endl;
}