因此,我從執行 HTML 請求中得到了以下 JSON:
{ "cities": [ { "plz": "91443", "name": "Scheinfeld" }, { "plz": "91448", "name": "Emskirchen" } ] }
我將此 JSON 保存在以下變數中:
json = JSON.parse( JSON.stringify(xhr.responseText));
console.log(json.cities[0].plz);
但是我收到以下錯誤訊息:
"Uncaught TypeError: Cannot read properties of undefined (reading '0') at XMLHttpRequest.xhr.onreadystatechange"
所以似乎試圖訪問 plzjson.cities[0].plz不是正確的方法。那我該怎么做才正確呢?
uj5u.com熱心網友回復:
parse只試
json = JSON.parse(xhr.responseText);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/357626.html
標籤:javascript html
上一篇:通過嵌套屬性獲取父物件
