admin管理员组文章数量:1268471
I must be missing something simple here, but I'm having trouble retrieving data from a JSON array response. I can access objects with identifiers that start with letters, but not ones that start with numbers.
For example, I can access
data.item[0].specs.overview.details
But I can't access
data.item[0].specs.9a99.details
I must be missing something simple here, but I'm having trouble retrieving data from a JSON array response. I can access objects with identifiers that start with letters, but not ones that start with numbers.
For example, I can access
data.item[0].specs.overview.details
But I can't access
data.item[0].specs.9a99.details
Share
Improve this question
edited Nov 1, 2014 at 6:28
tshepang
12.5k25 gold badges97 silver badges139 bronze badges
asked Apr 25, 2010 at 22:37
Archie EcArchie Ec
705 bronze badges
3
- 1 Argh, I should have known this. Thanks for all the quick answers! I'm going to accept the first one. – Archie Ec Commented Apr 25, 2010 at 22:44
- Don't forget to accept an answer. It's a good way to improve your chances of getting help in the future. – NG. Commented Apr 25, 2010 at 22:48
- Yup, I did, but the system won't let me accept answers for 15 minutes after the question is asked. Thanks for the info, though! I also voted up all the answers that were correct. – Archie Ec Commented Apr 25, 2010 at 23:03
5 Answers
Reset to default 5Use bracket notation
that is:
data.item[0].specs["9a99"].details
Identifier literals must not begin with a number because they would be confused with number literals. You need to use the bracket syntax in this case:
data.item[0].specs["9a99"].details
Try this,
data.items[0].specs["9a99"].details
A variable name in javascript cannot start with a numeral. That's the reason why it doesn't work.
Javascript doesn't like variables or identifiers that start with a number, this reference states that only:
Any variable name has to start with
_ (underscore)
$ (currency sign)
a letter from [a-z][A-Z] range
Unicode letter in the form \uAABB (where AA and BB are hex values)
are valid first characters.
本文标签:
版权声明:本文标题:Retrieving data from a JSON sub array in javascript, where identifier starts with an integer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741064827a2333351.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论