Red*_*ama -2 javascript json
我有一个变量json,当我称之为console.log(json)输出时{"buildingName":"", "addressLine1":"", "postcode":""}
json
console.log(json)
{"buildingName":"", "addressLine1":"", "postcode":""}
为什么,当我打电话时console.log(json.postcode),我会得到undefined什么?
console.log(json.postcode)
undefined
编辑
console.log(typeof json)确实输出'string'.感谢大家的帮助!
console.log(typeof json)
dec*_*eze 5
json仍然是一个字符串,你需要JSON.parse它将它变成一个对象.现在你试图访问未定义的属性postcode的String.
JSON.parse
postcode
String
归档时间:
7 年,7 月 前
查看次数:
335 次
最近记录: