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

时间:2021-03-09 19:41:17

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:

[
  {
    "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>

1 个解决方案

#1


0  

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.

你上面提供的代码工作正常,问题出在其他地方,可能在你遗漏的代码中,因为你认为它是不必要的。很明显我不知道你为什么会得到“991位JSON中的意外令牌”,你说你使用的是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

这是我制作的工作插件

#1


0  

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.

你上面提供的代码工作正常,问题出在其他地方,可能在你遗漏的代码中,因为你认为它是不必要的。很明显我不知道你为什么会得到“991位JSON中的意外令牌”,你说你使用的是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

这是我制作的工作插件