以下のjsonデータがあります:
{
"images": [
{
"candidates": [
{
"confidence": 0.80836,
"enrollment_timestamp": "20190613123728",
"face_id": "871b7d6e8bb6439a827",
"subject_id": "1"
}
],
"transaction": {
"confidence": 0.80836,
"enrollment_timestamp": "20190613123728",
"eyeDistance": 111,
"face_id": "871b7d6e8bb6439a827",
"gallery_name": "development",
"height": 325,
"pitch": 8,
"quality": -4,
"roll": 3,
"status": "success",
"subject_id": "1",
"topLeftX": 21,
"topLeftY": 36,
"width": 263,
"yaw": -34
}
}
]
}
subject_id
が上記のjsonデータに存在するかどうか。このために私は以下を行いました:
auto subjectIdIter = response.find("subject_id");
if (subjectIdIter != response.end())
{
cout << "it is found" << endl;
}
else
{
cout << "not found " << endl;
}
どうすれば解決できますか。ありがとう
画像と候補を含む検索を使用し、チェックします:
if (response["images"]["candidates"].find("subject_id") !=
response["images"]["candidates"].end())
候補は配列なので、オブジェクトを反復してfindを呼び出すだけです。
bool found = false;
for( auto c: response.at("images").at("candidates") ) {
if( c.find("subject_id") != c.end() ) {
found = true;
break;
}
}