2014-12-17 2 views
0

나는 rapidjson에 새로 온 사람, 나는 json 텍스트 아래에 있습니다 0, 1, 2; 3, 4, 5; 6, 7, 8"ports"의 :rapidjson에서 중복 키의 값을 얻었습니까?

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

가 어떻게 값을 추출 할 수 있을까?

미리 감사드립니다.

답변

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; 
}