I have an json object: [{a:"b"},{a:"c"},{a:"c"},{a:"d"},{a:"e"}] which is stored in a Json::Value object.
I seem to be having some trouble with filtering that JSON object down to say: where only "a" = "c"
I was trying to do the following:
Json::Value data (*result.GetValue());
std::string filterValue = message->GetData()["Filter"];
std::string filterKey("a");
//above was just a quick variable definition for my example.
for ( auto row = data.begin(); row != data.end(); ++row )
{
if ( *row[filterKey].asString().compare(filterValue) != 0 )
{
//Remove this row from the JSON object.
}
}
Normally i am a Javascript dev, but i wanted to filter the results in C++11 before sending it to the client. In Javascript it is just as simple as: [].filter(function(ele){ if (ele["a"] == "c") return true; return false; }); but that is no help here.
In the Json::Value api, i didnt see any sort of filtering functions.
EDIT: The other issue is i was not sure how everything would act in the loop if i removed the item... something like: row->clear() or similar
Aucun commentaire:
Enregistrer un commentaire