无法读取未定义的 属性 图片
Can not read property picture of undefined
我有以下JSON
{
"error": false,
"data": {
"id": 1,
"name": "Jagadesha NH",
"email": "example@gmail.com",
"phone": "9986XXXXXX",
"dob": "1991-06-01",
"gender": "m",
"active": 1,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04",
"profile": {
"id": 1,
"user_id": 1,
"picture": "https:\/\/placehold.it\/150x150",
"about": null,
"occupation": null,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04"
}
},
"msg": ""
}
每次我尝试阅读图片 属性 我都会收到一条错误消息
cannot read property picture of undefined
我正在阅读
data.profile.picture
我是这样发现的:
var x={
"error": false,
"data": {
"id": 1,
"name": "Jagadesha NH",
"email": "example@gmail.com",
"phone": "9986xxxxxx",
"dob": "1904-06-01",
"gender": "m",
"active": 1,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04",
"profile": {
"id": 1,
"user_id": 1,
"picture": "https:\/\/placehold.it\/150x150",
"about": null,
"occupation": null,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04"
}
},
"msg": ""
}
;
alert(x.data.profile.picture);
如果您将 json 存储在变量中,请使用变量访问它,然后使用点 (<<variable_name>>.data.profile.picture
)
你收到错误是因为数据本身是一个键或对象
的属性
var a = //Your json
a.data.profile.picture
我有以下JSON
{
"error": false,
"data": {
"id": 1,
"name": "Jagadesha NH",
"email": "example@gmail.com",
"phone": "9986XXXXXX",
"dob": "1991-06-01",
"gender": "m",
"active": 1,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04",
"profile": {
"id": 1,
"user_id": 1,
"picture": "https:\/\/placehold.it\/150x150",
"about": null,
"occupation": null,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04"
}
},
"msg": ""
}
每次我尝试阅读图片 属性 我都会收到一条错误消息
cannot read property picture of undefined
我正在阅读
data.profile.picture
我是这样发现的:
var x={
"error": false,
"data": {
"id": 1,
"name": "Jagadesha NH",
"email": "example@gmail.com",
"phone": "9986xxxxxx",
"dob": "1904-06-01",
"gender": "m",
"active": 1,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04",
"profile": {
"id": 1,
"user_id": 1,
"picture": "https:\/\/placehold.it\/150x150",
"about": null,
"occupation": null,
"created_at": "2017-02-19 21:33:04",
"updated_at": "2017-02-19 21:33:04"
}
},
"msg": ""
}
;
alert(x.data.profile.picture);
如果您将 json 存储在变量中,请使用变量访问它,然后使用点 (<<variable_name>>.data.profile.picture
)
你收到错误是因为数据本身是一个键或对象
的属性var a = //Your json
a.data.profile.picture