I tried but seems too many loops. Is there any optimal way?
Input JSON:
{"errors":[{"key":"XYZ","code":37373,"message":"Invalid XYZ Code"}]}
Hard code key in the solution, not an issue.
I have tried to print by below solution:
if(!aJsonDocument.Parse<0>(aResponseJson.c_str()).HasParseError())
{
for(rapidjson::Value::ConstMemberIterator iter = aJsonDocument.MemberBegin(); iter != aJsonDocument.MemberEnd(); ++iter)
{
if(iter->name.IsString() && iter->value.IsArray())
{
std::string aKey = iter->name.GetString();
const rapidjson::Value& aJsonData = aJsonDocument[aKey.c_str()];
if(aJsonData.IsArray())
{
for (rapidjson::SizeType i = 0; i < aJsonData.Size(); i++)
{
for(rapidjson::Value::ConstMemberIterator iter1 = aJsonData[i].MemberBegin(); iter1 != aJsonData[i].MemberEnd(); ++iter1)
{
std::string aKey = iter1->name.GetString();
boost::trim(aKey);
std::string aValue = iter1->value.GetString();
boost::trim(aValue);
std::cout<< "Key: " << aKey << ", Value:" << aValue << endl;;
}
}
}
}
}
}