2012-03-11 125 views
0

的下面的代码,我想创建一个JavaScript对象的线,给了我下面的错误:错误创建Javascript对象

Uncaught SyntaxError: Unexpected token {

这是代码行:

var flyer2 = {"id":20,"img_url":"http://images.awfbeat.com/48395b02-59e5-4e26-b7bc-8c603008c9c4","img_width":0,"img_height":0,"popularity":0,"color":"#67c547","tag":"Jul 10","category":"festivals","title":"Darth Vader\\\u0027s \\\"Annihilator\\\"","title_slug":"darth-vader-s-annihilator-","performer":"","performer_sort":"xxxx","posted":"2012-03-11 04:09:20.0","facebook_event_id":"","venue_postal":"90802","venue_name":" Aquarium of the Pacific","venue_street":"100 Aquarium Way","venue_city":"Los Angeles","venue_region_abbr":"CA","venue_lat":"33.762226","venue_lng":"-118.19686","needs_info":false}; 

我究竟做错了什么?

+0

在你真实的代码中是'"'...?至少把它改成'''。 – 2012-03-11 09:57:31

+0

As @ rob-w said,remove your "。这里有一个有用的工具来验证你的JSON数据:[JSONLint](http://jsonlint.com/) – Guumaster 2012-03-11 12:37:24

回答

2

你是HTML格式的报价。

不是100%肯定的,但我想&符号被解析为按位运算符和运算符,分号作为行尾符号。

1

如果这是服务器端代码,然后 解决办法是:

var flyer2 = "{"\""id"\"":20,"\""img_url"\"":"\""http://images.awfbeat.com/48395b02-59e5-4e26-b7bc-8c603008c9c4"\"","\""img_width"\"":0,"\""img_height"\"":0,"\""popularity"\"":0,"\""color"\"":"\""#67c547"\"","\""tag"\"":"\""Jul 10"\"","\""category"\"":"\""festivals"\"","\""title"\"":"\""Darth Vader\\\u0027s \\\"\""Annihilator\\\"\"""\"","\""title_slug"\"":"\""darth-vader-s-annihilator-"\"","\""performer"\"":"\"""\"","\""performer_sort"\"":"\""xxxx"\"","\""posted"\"":"\""2012-03-11 04:09:20.0"\"","\""facebook_event_id"\"":"\"""\"","\""venue_postal"\"":"\""90802"\"","\""venue_name"\"":"\"" Aquarium of the Pacific"\"","\""venue_street"\"":"\""100 Aquarium Way"\"","\""venue_city"\"":"\""Los Angeles"\"","\""venue_region_abbr"\"":"\""CA"\"","\""venue_lat"\"":"\""33.762226"\"","\""venue_lng"\"":"\""-118.19686"\"","\""needs_info"\"":false}"; 

其他

var flyer2 = {"id":20,"img_url":"http://images.awfbeat.com/48395b02-59e5-4e26-b7bc-8c603008c9c4","img_width":0,"img_height":0,"popularity":0,"color":"#67c547","tag":"Jul 10","category":"festivals","title":"Darth Vader\\\u0027s \\\"Annihilator\\\"","title_slug":"darth-vader-s-annihilator-","performer":"","performer_sort":"xxxx","posted":"2012-03-11 04:09:20.0","facebook_event_id":"","venue_postal":"90802","venue_name":" Aquarium of the Pacific","venue_street":"100 Aquarium Way","venue_city":"Los Angeles","venue_region_abbr":"CA","venue_lat":"33.762226","venue_lng":"-118.19686","needs_info":false}; 

或者使用单一配额。