tags:

views:

34

answers:

2

Hello,

I have the following JSON:

{
    "@id": "hey there",
    "id": "hey there 2"
}

I can easily parse "id" with json.id but how can I get the value of "@id" using jquery's inbuilt JSON parser?

As calling "json.@id" is not correct.

Thanks

+2  A: 

Try:

json['@id']

Also note that the JSON object you've posted is not valid: you are missing a , between the two properties.

Darin Dimitrov
@Darin you ve been providing all the answers for questions related to json for me and other users also.. So +1
Pandiya Chendur
Obviously. Sigh. One of those days. Thanks
James moore
+1  A: 

In addition to above answer, you can use http://jsonlint.com to validate your json

redsquare
I don't really see how that's relevant.
Dave Van den Eynde
@Dave Van den Eynde It was because his json was invalid...
redsquare
Yes, but the question was not if the JSON is valid or not, but how to access properties with names that are not valid identifiers.
Dave Van den Eynde
Still, it's a useful tool you pointed out.
Dave Van den Eynde
@Dave Van den Eynde Sigh - Note the "In additon to the above" bit
redsquare