ASP.NET MVC返回产品型号代码,使用ff和谷歌浏览器都返回了如下的数据:
[{"ProductType":"JD4DBD-2D17-A1B2"},{"ProductType":"JD4BW1W-7SP7-A1B2"}],经在校验验,确定json格式正确,但却提示SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data。请各位大佬帮忙看看哪儿错了。新人初来,没有分数,还请见谅。
html端js代码如下:
$("#txtAutoComplete").typeahead({
source: function (query, process) {
return $.ajax({
url: "/OrderForm/GetProductTypeByType",
data: { "productType":query },
type: "POST",
dataType: "json",
success: function (result) {
var json = JSON.parse(result);
var resultList = json.topicList.map(function (item) {
var aItem = { ProductType: item.ProductType };
return JSON.stringify(aItem);
});
return process(resultList);
}
});
}
});
用 单引号包裹,
以下一个例子提供参考
JSON.parse('{"name":"huangxiaojian","age":"23"}') ==> Object {name: "huangxiaojian", age: "23"}
console.log(result)
一下看看,是不是有多余的东西
dataType: "json"
返回值本来就是json对象,你还拿json对象去转json对象 不报错报什么 ??
还有这 return JSON.stringify(aItem); 难道对象在你的方法里不能用吗 还有特意转成json字符串传过去?