最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Object Uncaught SyntaxError: Unexpected number - Stack Overflow

programmeradmin1浏览0评论

Using:

console.log("First Item Author: "+myjson.value.items.0.author);

I get the following error:

Object Uncaught SyntaxError: Unexpected number 

Trying to access the following object:

Using:

console.log("First Item Author: "+myjson.value.items.0.author);

I get the following error:

Object Uncaught SyntaxError: Unexpected number 

Trying to access the following object:

Share Improve this question edited Aug 27, 2013 at 17:21 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked Aug 27, 2013 at 17:05 Hydra IOHydra IO 1,5611 gold badge13 silver badges29 bronze badges 3
  • 1 That's Javascript. It has nothing to do with jQuery. – SLaks Commented Aug 27, 2013 at 17:11
  • It has nothing to do with JSON either. – Felix Kling Commented Aug 27, 2013 at 17:21
  • possible duplicate of Access / process (nested) objects, arrays or JSON – Felix Kling Commented Aug 27, 2013 at 17:21
Add a ment  | 

2 Answers 2

Reset to default 4

0 is not a valid identifier and cannot be used as a direct property name.

Instead, use array notation:

items[0].author

0 is not a valid identifier name. Use bracket notation instead of dot notation:

console.log("First Item Author: " + myjson.value.items[0].author);
发布评论

评论列表(0)

  1. 暂无评论