jsoncpp. найти объект в массиве, сопоставив значение
У меня есть этот объект JSON:
{"books":[
{
"author" : "Petr",
"book_name" : "Test1",
"pages" : 200,
"year" : 2002
},
{
"author" : "Petr",
"book_name" : "Test2",
"pages" : 0,
"year" : 0
},
{
"author" : "STO",
"book_name" : "Rocks",
"pages" : 100,
"year" : 2002
}
]
}
Например, мне нужно найти книгу (ы), которыеauthor
ключ равенPetr
, Как я могу это сделать? Прямо сейчас у меня есть этот кусок кода:
Json::Value findBook(){
Json::Value root = getRoot();
cout<<root["books"].toStyledString()<<endl; //Prints JSON array of books mentioned above
string searchKey;
cout<<"Enter search key: ";
cin>>searchKey;
string searchValue;
cout<<"Enter search value: ";
cin>>searchValue;
Json::Value foundBooks = root["books"]???; // How can I get here a list of books where searchKey is equal to searchValue?
}
Заранее спасибо.