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

json - Unexpected token ILLEGAL javascript error in Google Chrome - Stack Overflow

programmeradmin3浏览0评论

I am getting a javascript (prototype.js) error: Unexpected token ILLEGAL at this line of code:

newFriend = new friend(
    response[0].@items[0]._id, 
    response[0].@items[0]._nickName, 
    response[0].@items[0]._profilePicture, 
    response[0].@items[0]._tagLine, 
    response[0].@items[0]._isInvite, 
    response[0].@items[0]._confirm
);

the response object looks like this:

[{
  "@type": "[L.photoviewermon.model.ThinUser;",
  "@items": [{
    "_id": "000.060318.05022007.00263.0067ur",
    "_nickName": "siraj",
    "_country": null,
    "_currentStorageLimit": 5000000000,
    "_currentStorage": 0,
    "_currentFileCount": 0,
    "_profilePicture": null,
    "_tagLine": null,
    "_membershipLevel": 0,
    "_isRejected": false,
    "_isInvite": false,
    "_confirm": false,
    "_verifiedOn": 1170716666000
  }]
}]

This is only happening in the Google Chrome browser and possibly other webkit browsers. It works fine in Firefox.

I am getting a javascript (prototype.js) error: Unexpected token ILLEGAL at this line of code:

newFriend = new friend(
    response[0].@items[0]._id, 
    response[0].@items[0]._nickName, 
    response[0].@items[0]._profilePicture, 
    response[0].@items[0]._tagLine, 
    response[0].@items[0]._isInvite, 
    response[0].@items[0]._confirm
);

the response object looks like this:

[{
  "@type": "[L.photoviewer.mon.model.ThinUser;",
  "@items": [{
    "_id": "000.060318.05022007.00263.0067ur",
    "_nickName": "siraj",
    "_country": null,
    "_currentStorageLimit": 5000000000,
    "_currentStorage": 0,
    "_currentFileCount": 0,
    "_profilePicture": null,
    "_tagLine": null,
    "_membershipLevel": 0,
    "_isRejected": false,
    "_isInvite": false,
    "_confirm": false,
    "_verifiedOn": 1170716666000
  }]
}]

This is only happening in the Google Chrome browser and possibly other webkit browsers. It works fine in Firefox.

Share Improve this question edited Dec 30, 2019 at 16:02 Mickael Lherminez 6951 gold badge11 silver badges30 bronze badges asked Jan 28, 2010 at 19:35 DustinDustin 8,26711 gold badges35 silver badges45 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Try this instead:

newFriend = new friend(
    response[0]["@items"][0]._id, 
    response[0]["@items"][0]._nickName, 
    response[0]["@items"][0]._profilePicture, 
    response[0]["@items"][0]._tagLine, 
    response[0]["@items"][0]._isInvite, 
    response[0]["@items"][0]._confirm
);

I'm pretty sure @ is giving you a problem.

For weird characters it's always safer to use the ["@items"] notation instead of the (dot) notation .@items.

Property names containing @ and dot notation are inpatible in Chrome. Use square bracket notation instead (you already do when you construct the object).

发布评论

评论列表(0)

  1. 暂无评论