0

input of json string as [ { "description" : "sample"", "id" : 3, "name" : "xyz", "numOfSnapshots" : 132, "storagePool" : 1, "volSize" : 32 },]

how to extract the list and get the key and value

sai
  • 1
  • 1

1 Answers1

0
std::vector<std::string> keys = json.getMemberNames();
for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it)
{
    if (json[*it].isString())
    {
        std::string value = json[*it].asString();
    }
    else if (json[*it].isInt())
    {
         int value = json[*it].asInt();
    }
    // and so on for each type...
}

...If you have boost, you can replace the loop with a very elegant:

BOOST_FOREACH(const std::string &key, json.getMemberNames())
Sga
  • 3,608
  • 2
  • 36
  • 47