如何正确使用 Scott Klement 的 YAJL 库来读取 Watson Visual Recognition 的响应?json 对象如下所示:
{
"images": [
{
"classifiers": [
{
"classifier_id": "default",
"name": "default",
"classes": [
{
"class": "outside mirror",
"score": 0.85,
"type_hierarchy": "/reflector/mirror/outside mirror"
},
{
"class": "mirror",
"score": 0.998
},
{
"class": "reflector",
"score": 0.998
},
{
"class": "car mirror",
"score": 0.764,
"type_hierarchy": "/reflector/mirror/car mirror"
},
{
"class": "rearview mirror",
"score": 0.714,
"type_hierarchy": "/reflector/mirror/rearview mirror"
},
{
"class": "ash grey color",
"score": 0.778
},
{
"class": "bottle green color",
"score": 0.532
}
]
}
],
"source_url": "https://.jpg",
"resolved_url": "https://.jpg"
}
],
"images_processed": 1,
"custom_classes": 0
}
现在我想从具有类 score_hierarchy 的类对象中获取值。我怎样才能到达 classes 数组?获取图像对象后,我找不到分类器继续...
docNode = yajl_stmf_load_tree( temporaryFile: errMsg);
if errMsg <> '';
return imageClasses;
endif;
i = 0;
images = YAJL_OBJECT_FIND(docNode: 'images');
dow yajl_array_loop(images: i: node);
// TODO: How to continue to get "classifiers" object?
j = 0;
dow yajl_object_loop(node:j:key:val);
select;
when key = 'classes';
imageClasses(i).class = yajl_get_string(val);
when key = 'score';
imageClasses(i).score = yajl_get_number(val);
when key = 'type_hierarchy';
imageClasses(i).typeHierarchy = yajl_get_string(val);
endsl;
enddo;
enddo;
yajl_tree_free(docNode);