Reputation: 110960
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
Upvotes: 3
Views: 6048
Reputation: 1
{
"member":{
"id":value
},
{
another_data:value
}
}
the data are accesses using the(.) operator. the id is accessed by member.id
Upvotes: 0
Reputation: 18833
var 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.
Upvotes: 6
Reputation: 157
You're missing the curly braces surrounding the object. As in:
var x = {'member': [{'id':8286}]};
Upvotes: 3