Google Cloud Vision API 响应结构

Google Cloud Vision API response structure

在调用 vision.documentTextDetection()

时获得此响应
[{ 
    faceAnnotations: [],
    landmarkAnnotations: [],
    logoAnnotations: [],
    labelAnnotations: [],
    textAnnotations: [],
    localizedObjectAnnotations: [],
    safeSearchAnnotation: null,
    imagePropertiesAnnotation: null,
    error: null,
    cropHintsAnnotation: null,
    fullTextAnnotation: null,
    webDetection: null,
    context: null 
}]

有些属性为空数组,有些为空数组有什么意义?
我正在尝试进行条件渲染,但在 IRL 不是真实值时卡在了真实值上。

我不能代表 API 的创建者,但就您编写更少的代码来完成更多的工作而言,这是有道理的。

如果有问题的数组字段始终是数组而不是其他任何东西,那么您只需在代码中假设它们是数组即可。这意味着如果您想知道该数组中是否返回了某些内容安全,那么您所要做的就是检查数组的长度,或者只是迭代它。

另一方面,如果有问题的数组字段是有时个数组,可能是null,那么你必须编写代码首先检查数组字段是否为null,然后编写代码来检查数组。

你更愿意做什么? 1)假设该字段是一个数组并对其进行处理。或者 2) 检查它是否实际上是一个数组,然后这样处理它?在我看来,假设数组更方便,并且编写更少的代码。