I have a REST service that returns a JSON like this:
[{"@id":"123","name":"Name"}]
and I’m tearing my hair out trying to figure out how the hell to get the value for @id. I’ve tried:
var temp = data['@id'];
var temp = data[0].'@id';
var temp = data[0].['@id'];
all of which return errors. Can someone please help me out here?
var temp = data[0]['@id'];Using
.propertyonly accepts symbols you can use in identifiers and is identical to["property"]. Since you have array with single object with"@id"property and @ can’t be used in identifiers, you have to use brackets. This above translates to data -> it’s 0th index (index count start from 0) -> its property “@id”.