I have the following json:
{
"laureates": [{
"id": "1",
"firstname": "Wilhelm Conrad",
"surname": "Röntgen",
"born": "1845-03-27",
"died": "1923-02-10",
"bornCountry": "Prussia (now Germany)",
"bornCountryCode": "DE",
"bornCity": "Lennep (now Remscheid)",
"diedCountry": "Germany",
"diedCountryCode": "DE",
"diedCity": "Munich",
"gender": "male",
"prizes": [{
"year": "1901",
"category": "physics",
"share": "1",
"motivation": "\"in recognition of the extraordinary services he has rendered by the discovery of the remarkable rays subsequently named after him\""
}]
}]
}
I have tried this:
bool ok = reader.parse(txt, root, false);
if(! ok)
{
std::cout << "failed parse\n";
}
std::vector<std::string> keys = root.getMemberNames();
for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it)
{
if (root[*it].isString())
{
std::string value = root[*it].asString();
std::cout << value << std::endl;
}
else if (root[*it].isInt())
{
int value = root[*it].asInt();
std::cout << value << std::endl;
}
else if (root[*it].isArray()){
// what to do here?
}
}
The code works fine, but the problem is when I have an array like "prizes". I can't realize how to iterate and show the values without hardcoded it.
Can anyone help me with this?
Thanks in advance.