【问题标题】:How do I access the inner data in this Google Custom Search errors array?如何访问此 Google 自定义搜索错误数组中的内部数据?
【发布时间】:2026-02-14 20:20:05
【问题描述】:

我有一个通过 REST 使用 Google 自定义搜索的网络应用。到目前为止,一切正常,但是当我超过分配的每日查询配额时,我想给用户一些关于它的信息。我得到这个 JSON 响应,我可以使用 response.error.code 和 response.error.message 访问“代码”和“消息”数据,但我不知道如何访问子集“错误”,特别是“原因” ”。

我知道这是一个 JSON 问题,但我对此没有太多经验。 这是我收到的 JSON 结构(这是我所期望的)

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceeded",
    "message": "This API requires billing to be enabled on the project. Visit https://console.developers.google.com/billing?project=323544036192 to enable billing.",
    "extendedHelp": "https://console.developers.google.com/billing?project=323544036192"
   }
  ],
  "code": 403,
  "message": "This API requires billing to be enabled on the project. Visit https://console.developers.google.com/billing?project=323544036192 to enable billing."
 }
}

【问题讨论】:

    标签: json google-custom-search


    【解决方案1】:

    我找到了尝试不同事物的解决方案。我想我很幸运。

    console.log(response.error.errors[0].reason);
    

    这为我提供了我试图访问的数据。

    【讨论】: