0

I'm new to rapidjson, and I have below json text:

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

How could I extract the values: 0, 1, 2; 3, 4, 5; 6, 7, 8 by key "ports"?

Thanks in advance.

Rizier123
  • 58,877
  • 16
  • 101
  • 156

1 Answers1

0

Ah, I have got it works as below code:

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