0

Trying to create JSONs on the fly for my application, but the JSON I recieve does not remain constant.

std::string ResponseJson::getValue(std::string filter, std::string      filterName, std::string jsonIndex)
{
 BOOST_FOREACH(boost::property_tree::ptree::value_type & arrayElement, root.get_child("message"))
{
    std::string value = arrayElement.second.get<std::string>(filter);
    if (value == filterName)
    {
        return arrayElement.second.get<std::string>(jsonIndex);
    }
}
return "";
}

above code snippet works well but message is the child which can be changed in different jsons so how can I make this function generic ?

CMouse
  • 130
  • 3
  • 19
  • If you can change the signature of function `getValue`, pass the the name of the child as parameter and replace string literal `"message"` with that parameter. Or isn't class `ResponseJson` yours? – Stephan Lechner Mar 06 '17 at 09:23
  • I do own the class but in that case I have to check every case and send the parameter accordingly, but that won't simplify the things and that won't be a good solution for the usecase but a good workaround. – CMouse Mar 06 '17 at 10:29

0 Answers0