Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建Javascript对象时出错_Javascript_Json_Syntax Error - Fatal编程技术网

创建Javascript对象时出错

创建Javascript对象时出错,javascript,json,syntax-error,Javascript,Json,Syntax Error,下面的代码行(我认为它创建了一个javascript对象)给出了以下错误: 未捕获的语法错误:意外标记{ 这是代码行: var flyer2 = {"id":20,"img_url":"http://images.awfbeat.com/48395b02-59e5-4e26-b7bc-8c603008c9c4","img_width":0,&am

下面的代码行(我认为它创建了一个javascript对象)给出了以下错误:

未捕获的语法错误:意外标记{

这是代码行:

    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};

我到底做错了什么?

您正在用html编码引号


不是100%确定,但我猜符号and被解析为按位and运算符,分号被解析为行尾符号。

您正在对引号进行html编码


不是100%确定,但我猜符号and被解析为按位and运算符,分号被解析为行尾符号。

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

 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}";
否则

或者使用单一配额。

在您的真实代码中是否存在
”?至少将其更改为
。正如@rob-w所说,删除您的。这里有一个有用的工具来验证您的JSON数据:在真实代码中是否存在
。至少将其更改为
。正如@rob-w所说,删除您的”。这里有一个有用的工具来验证JSON数据: