创建Javascript对象时出错

时间:2012-03-11 09:54:37

标签: javascript json syntax-error

下面的代码行,我认为它创建了一个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};

我究竟做错了什么?

2 个答案:

答案 0 :(得分:2)

你是html编码引号。

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

答案 1 :(得分: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};

或者使用单引号。