未捕获的语法错误意外的令牌U JSON
当我使用chrome运行我的页面时,出现此错误“uncaught syntaxerror unexpected token U”。 并在Firefox中,我得到,“JSON.parse:意想不到的人物”。 我从PHP文件返回json数据,返回的json字符串是有效的。 我用http://jsonlint.com/检查了它。 任何帮助将不胜感激......谢谢。
这是返回的JSON字符串
[
["1","Pan Africa Market",""1521 1st Ave, Seattle, WA"","47.608941","-122.340145","restaurant"],
["2","The Melting Pot","14 Mercer St, Seattle, WA","47.624562","-122.356442","restaurant"],
["3","Ipanema Grill","1225 1st Ave, Seattle, WA","47.606366","-122.337656","restaurant"],
["4","Sake House","230 1st Ave, Seattle, WA","47.612825","-122.34567","bar"],
["5","Crab Pot","1301 Alaskan Way, Seattle, WA","47.605961","-122.34036","restaurant"],
["6","Mexican Kitchen","2234 2nd Ave, Seattle,WA","47.613975","-122.345467","bar"],
["7","Wingdome","1416 E Olive Way, Seattle, WA","47.617215","-122.326584","bar"],
["8","Piroshky Piroshky","1908 Pike pl, Seattle, WA","47.610127","-122.342838","restaurant"]
]
当给JSON.parse
的值实际上是undefined
时,通常会看到该错误。 所以,我会检查试图解析这个的代码 - 很可能你没有解析这里显示的实际字符串。
在验证时(在MVC项目中),我收到了这条消息。 对我而言,添加ValidationMessageFor元素解决了问题。
确切地说,jquery.validate.unobtrusive.js中的第43行导致了这个问题:
replace = $.parseJSON(container.attr("data-valmsg-replace")) !== false;
发生此错误的最常见情况是使用生成控件的模板,然后通过类似'覆盖'默认模板来更改id
和/或name
的生成方式
@Html.TextBoxFor(m => m, new {Name = ViewData["Name"], id = ViewData["UniqueId"]} )
然后忘记将ValidationMessageFor
更改为
@Html.ValidationMessageFor(m => m, null, new { data_valmsg_for = ViewData["Name"] })
希望这可以为你节省一些时间。
链接地址: http://www.djcxy.com/p/45943.html