admin管理员组文章数量:1287817
I want to create the following JSON object, as seen from a console log:
Object
. member: Object
. id: 8286
I've been trying:
'member' :[{'id': 8286}]
but get the following error: "Uncaught SyntaxError: Unexpected token :"
What am I doing wrong? Thanks
I want to create the following JSON object, as seen from a console log:
Object
. member: Object
. id: 8286
I've been trying:
'member' :[{'id': 8286}]
but get the following error: "Uncaught SyntaxError: Unexpected token :"
What am I doing wrong? Thanks
Share Improve this question asked Jan 6, 2012 at 21:26 AnApprenticeAnApprentice 111k202 gold badges637 silver badges1k bronze badges 9- bonsaiden.github./JavaScript-Garden – Zirak Commented Jan 6, 2012 at 21:29
- 4 I don't upvote to pensate downvotes, but I should. This is a perfectly valid question. – Julio Santos Commented Jan 6, 2012 at 21:29
- 1 @JúlioSantos, that's a good rule, though. You might think the question deserves to be at zero, but you are giving the requestor +8 rep. In this case, that's probably fine, but in general it often rewards bad or mediocre questions. – Devin Burke Commented Jan 6, 2012 at 21:32
- Try to you something like jshint. – jake Commented Jan 6, 2012 at 21:32
- 3 Do you want to create JSON or a JavaScript object? Have you read a JavaScript Guide at all? – Felix Kling Commented Jan 6, 2012 at 21:38
4 Answers
Reset to default 6var member = {
id: 8286
};
this allows you to access it like
member.id
You could have also meant something like:
var data = {
member: {
id: 8286
}
};
which you would access like so:
data.member.id
If this is not what you want, please clarify in your post cause I'm not sure I'm following your request correctly.
You're missing the curly braces surrounding the object. As in:
var x = {'member': [{'id':8286}]};
You mean something like this?
{
"member": {},
"id": 8286
}
{
"member":{
"id":value
},
{
another_data:value
}
}
the data are accesses using the(.) operator. the id is accessed by member.id
本文标签: javascriptHow to make a JSON objectStack Overflow
版权声明:本文标题:javascript - How to make a JSON object? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741277135a2369793.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论