【发布时间】:2015-03-10 06:05:45
【问题描述】:
我有这个 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?
}
提前致谢。
【问题讨论】:
-
你一直在说“它不起作用”。请养成提供具体问题描述以及证据的习惯。 “不行”基本没用。
-
@LightnessRacesinOrbit 嗨。我真的很抱歉。我已将 Barry 解决方案标记为正确,这是真的。就我而言,问题出在 Jetbrains 的 IDE CLion 上,它目前仅作为 EAP 版本提供。 IDE 有一些错误,在编译项目后它启动了旧应用程序。