How to read Data with key values from Json

{
“Question”:[{
“ID”:“1”,
“ImageURL”:“Resource/india.png”,
“CorrectAns”:“India”,
“Options”: [“India”, “USA”, “China”, “England”]
},
{
“ID”:“2”,
“ImageURL”:“Resource/USA.png”,
“CorrectAns”:“India”,
“Options”: [“China”, “USA”, “India”, “England”]
}]
}

Please help me how to load above data in map or vector and if I give key then value will be display can anybody give me code

You can:

  1. learn rapidjson's API and write your own extraction or conversion for your specific needs.
  2. You can find a few examples in the forums on converting into Value{Vector,Map}
  3. Convert your JSON into PLISTs w/external tool and use directly with Value{Vector,Map}
  4. Use a “more friendly” json library like jsoncpp or similar.

#2 Convert into Value{Vector,Map}

#4 use a different library
http://json.org/ - listing of many libraries
Rapidjson vs JsonCPP
How to read a file of json?C++

#1 jsonhelper code

#3 external tool

void HelloWorld::loadJsonFile()
{
static int i = 0;
static int count= 0;
std::string id;
rapidjson::Document document;
std::string data = “doc.json”;
std::string content = FileUtils::getInstance()->getStringFromFile(data.c_str());
document.Parse<0>(content.c_str());

if(document.HasMember(“level5”))
{
const rapidjson::Value& questionArray = document[“level5”];
for(rapidjson::Value::ConstMemberIterator itr = questionArray.MemberBegin(); itr != questionArray.MemberEnd(); ++itr)
{
std::string id = itr->name.GetString();
log(“Question id = %s”, id.c_str());
const rapidjson::Value& objName = questionArray[itr->name.GetString()];
vector words;
for(short int i=0; i<objName.Size(); i++)
{
words.push_back(objName[i].GetString());
}

if(words.size()>0)
{
  jsonMap[id] = words; 
  //jsonMap.insert(pair<std::string, vector<std::string>> (id, words));
}

}
}

map<std::string, vectorstd::string>::iterator m;
static vector::iterator it;
for(m = jsonMap.begin(); m != jsonMap.end(); m++)
{
log(“Key : %s”, m->first.c_str());
for( it = m->second.begin(); it != m->second.end(); ++it)
{
log(“Values : %s”, it->c_str());
}
}