There is a file:

{ "item_gold_coin": { "name": "Gold Coin", "description": "A small disc made of lustrous metal" }, "item_iron_key": { "name": "Iron Key", "description": "A heavy iron key with a simple cut" } } 

Using the jsoncpp library, I will iterate through the elements ( item_* ) in the file:

 for(auto entity : root){ ... } 

And I need to get the name from the entity . How can I do it?

    1 answer 1

    You can get Json::Value::Members using the Value::getMembers() method. Walk through the received container with an iterator, and you will have both names and values:

     for(Json::Value::Members::const_iterator it = mem.begin(); it != mem.end(); ++it) { /* *it - ключ, val[*it] - значение */ } 

    Accordingly, val is of the type Json::Value , Json::Value::Members mem = val.getMembers() ;