简体   繁体   English

使用Angular.js时在JSON错误中获取意外令牌

[英]Getting Unexpected token in JSON error while using Angular.js

I have an error. 我有一个错误。 I am getting the following error while calling json data using $http in Angular.js. 在Angular.js中使用$http调用json数据时出现以下错误。

Error: 错误:

  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
)

I am providing my code below. 我在下面提供我的代码。

customer.json: 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"
  }
  ]

My controller side code is given below. 我的控制器端代码如下。

 $http.get('customer.json').success(function(data) {
    console.log('data',data);
    $scope.listOfCustomerData=data;
  })

My view code is given below. 我的查看代码如下。

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

The code you provided above is working fine, the problem is some where else, probably in the code which you have left out because you think its unnecessary. 上面提供的代码可以正常工作,问题出在其他地方,可能是在您遗漏的代码中,因为您认为这是不必要的。 so obviously I don't know why are you getting " Unexpected token in JSON at position 991 " also you said you are using 1.4.6 whereas your error says you are using 1.5.6. 因此,显然我不知道您为什么会收到“ Unexpected token in JSON at position 991 ”,同时您还说您正在使用1.4.6,而您的错误却表明您正在使用1.5.6。

Also a suggestion you could simply do: 您也可以简单地建议:

<tr dir-paginate="cus in listOfCustomerData | filter:q | itemsPerPage: pageSize" current-page="currentPage">

Instead of making it complicated: 而不是使其变得复杂:

<tr dir-paginate="cus in ($parent.labelResults=(listOfCustomerData  | filter:searchProduct.rest_name:startsWith | orderBy:'rest_name')) | itemsPerPage:pageSize track by $index" current-page="currentPage">

Here is the working plunker i made 这是我做的工作中的笨蛋

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM