2017-11-28 1 views
0

REST를 통해 Google 맞춤 검색을 사용하는 웹 앱이 있습니다. 지금까지 모든 것이 잘 작동하지만 할당 된 일일 할당량을 초과하면 사용자에게 몇 가지 정보를 제공하려고합니다. 이 JSON 응답을 얻었고 response.error.code 및 response.error.message를 사용하여 "code"및 "message"데이터에 액세스 할 수 있지만 "오류"라는 하위 집합에 액세스하는 방법을 알지 못합니다. 특히 "reason ".이 Google 맞춤 검색 오류 배열의 내부 데이터에 액세스하려면 어떻게해야합니까?

이 질문은 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." 
} 
} 

답변

0

(이 내가 기대하는 것입니다). 나는 운이 좋은 것 같아.

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

이렇게하면 액세스하려는 데이터가 표시됩니다.

관련 문제