admin管理员组文章数量:1253727
I need to get the data "messages" from this JSON object. How can I do it in JavaScript?
To access for example the lastname I just use:
response[i].user.lastname
But how can I access the messages?
[
{
"user": {
"last_message": {
"message": {
"created_at": "2011-04-16T16:40:56Z",
"updated_at": "2011-04-16T16:40:56Z",
"to": null,
"id": 10,
"user_id": 28,
"message": "This is a message"
}
},
"nickname": "thenicky",
"id": 28,
"lastname": "white",
"firstname": "Sean",
"bio": "A short bio",
"email": "[email protected]"
}
}
]
I need to get the data "messages" from this JSON object. How can I do it in JavaScript?
To access for example the lastname I just use:
response[i].user.lastname
But how can I access the messages?
[
{
"user": {
"last_message": {
"message": {
"created_at": "2011-04-16T16:40:56Z",
"updated_at": "2011-04-16T16:40:56Z",
"to": null,
"id": 10,
"user_id": 28,
"message": "This is a message"
}
},
"nickname": "thenicky",
"id": 28,
"lastname": "white",
"firstname": "Sean",
"bio": "A short bio",
"email": "[email protected]"
}
}
]
Share
Improve this question
edited Apr 15, 2017 at 21:25
halfer
20.5k19 gold badges108 silver badges202 bronze badges
asked Apr 16, 2011 at 22:05
Jonathan ClarkJonathan Clark
20.5k29 gold badges116 silver badges177 bronze badges
3 Answers
Reset to default 8response[i].user.last_message.message.created_at
And here's a live demo.
response[i].user.last_message.message
Some examples:
alert(response[0].user.last_message.message.id);
alert(response[0].user.nickname);
alert(response[0].user.lstname);
and working code:
JSFiddle Working Example
本文标签: Access data in a JSON object (parsed) in JavaScriptStack Overflow
版权声明:本文标题:Access data in a JSON object (parsed) in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740777517a2284528.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论