javascript - Calling numeric JSON field-names -
i'm using simple rest api project , of data need uses numeric string top-level parent node. when attempting call in javascript, throws syntax errors.
here's json object:
{"23497400":{"id":23497400,"name":foobar,"profileiconid":627,"revisiondate":1431385425000}}
and here's i'm throwing error:
var myarr = json.parse(xmlhttp.responsetext); var name1 = myarr.23497400.name;
there's terribly simple i'm missing, right?
you need use bracket notation if key not valid identifier name.
var name1 = myarr['23497400'].name;
when use dot notation,
property must valid javascript identifier, i.e. sequence of alphanumerical characters, including underscore ("_") , dollar sign ("$"), cannot start number. example, object.$1 valid, while object.1 not.
Comments
Post a Comment