我有错误。我在Angular.js中使用$http
调用json数据时收到以下错误。
错误:
SyntaxError: Unexpected token
in JSON at position 991
at Object.parse (native)
at Object.parse (native)
at wc (https://code.angularjs.org/1.5.6/angular.min.js:17:36)
at dc (https://code.angularjs.org/1.5.6/angular.min.js:91:424)
at https://code.angularjs.org/1.5.6/angular.min.js:92:337
at q (https://code.angularjs.org/1.5.6/angular.min.js:7:355)
at gd (https://code.angularjs.org/1.5.6/angular.min.js:92:319)
at c (https://code.angularjs.org/1.5.6/angular.min.js:94:72)
at https://code.angularjs.org/1.5.6/angular.min.js:130:409
at m.$eval (https://code.angularjs.org/1.5.6/angular.min.js:145:107)
at m.$digest (https://code.angularjs.org/1.5.6/angular.min.js:142:173
)
我在下面提供我的代码。
customer.json:
[
{
"rest_name": "Anjum",
"id":"1",
"address":"Goa",
"city":"1",
"country":"India",
" date":"2016-07-05 11:39:04",
"image":"",
"member_id":"135",
"mobile":"9937229853",
"person":"Subhrajyoti pradhan",
"postal":"752109",
"premium":"1",
"proviance":"Goa",
"quad_id":"3",
"quadrant":"3",
"quadrant_name":"SW",
"status":"1",
"url":"http://orimark.com"
},{
" rest_name": "A&P Chinese Food Express",
"id":"2",
"address":"Goa",
"city":"1",
"country":"India",
" date":"2016-07-05 11:39:04",
"image":"",
"member_id":"135",
"mobile":"9937229853",
"person":"Subhrajyoti pradhan",
"postal":"752109",
"premium":"1",
"proviance":"Goa",
"quad_id":"3",
"quadrant":"3",
"quadrant_name":"SW",
"status":"1",
"url":"http://orimark.com"
},{
" rest_name": "Bookers BBQ & Crab Shack",
"id":"3",
"address":"Goa",
"city":"1",
"country":"India",
" date":"2016-07-05 11:39:04",
"image":"",
"member_id":"135",
"mobile":"9937229853",
"person":"Subhrajyoti pradhan",
"postal":"752109",
"premium":"1",
"proviance":"Goa",
"quad_id":"3",
"quadrant":"3",
"quadrant_name":"SW",
"status":"1",
"url":"http://orimark.com"
},{
"rest_name": "Butcher And The Baker",
"id":"4",
"address":"Goa",
"city":"1",
"country":"India",
" date":"2016-07-05 11:39:04",
"image":"",
"member_id":"135",
"mobile":"9937229853",
"person":"Subhrajyoti pradhan",
"postal":"752109",
"premium":"1",
"proviance":"Goa",
"quad_id":"3",
"quadrant":"3",
"quadrant_name":"SW",
"status":"1",
"url":"http://orimark.com"
},{
"rest_name": "Cactus Club Stephen Avenue",
"id":"5",
"address":"Goa",
"city":"1",
"country":"India",
" date":"2016-07-05 11:39:04",
"image":"",
"member_id":"135",
"mobile":"9937229853",
"person":"Subhrajyoti pradhan",
"postal":"752109",
"premium":"1",
"proviance":"Goa",
"quad_id":"3",
"quadrant":"3",
"quadrant_name":"SW",
"status":"1",
"url":"http://orimark.com"
},{
"rest_name": "Cactus Club - Macleod Trail",
" id":"6",
"address":"Goa",
"city":"1",
"country":"India",
" date":"2016-07-05 11:39:04",
"image":"",
"member_id":"135",
"mobile":"9937229853",
"person":"Subhrajyoti pradhan",
"postal":"752109",
"premium":"1",
"proviance":"Goa",
"quad_id":"3",
"quadrant":"3",
"quadrant_name":"SW",
"status":"1",
"url":"http://orimark.com"
}
]
我的控制器端代码如下所示。
$http.get('customer.json').success(function(data) {
console.log('data',data);
$scope.listOfCustomerData=data;
})
我的观看代码如下。
<tbody id="detailsstockid">
<tr dir-paginate="cus in ($parent.labelResults=(listOfCustomerData | filter:searchProduct.rest_name:startsWith | orderBy:'rest_name')) | itemsPerPage:5 track by $index" current-page="currentPage">
<td>{{$index+1}}</td>
<td>{{cus.rest_name}}</td>
</tr>
</tbody>
答案 0 :(得分:0)
您上面提供的代码工作正常,问题出在其他地方,可能是您遗漏的代码,因为您认为这是不必要的。很明显我不知道你为什么会得到“Unexpected token in JSON at position 991
”你说你使用1.4.6而你的错误说你使用的是1.5.6。
也是一个你可以做的建议:
<tr dir-paginate="cus in listOfCustomerData | filter:q | itemsPerPage: pageSize" current-page="currentPage">
而不是让它变得复杂:
<tr dir-paginate="cus in ($parent.labelResults=(listOfCustomerData | filter:searchProduct.rest_name:startsWith | orderBy:'rest_name')) | itemsPerPage:pageSize track by $index" current-page="currentPage">