0

我是新手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"

提前致谢。

4

1 回答 1

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;
}
于 2014-12-17T09:18:58.763 回答