Reputation: 83
Console: SyntaxError: Unexpected token { in JSON at position 119
Xcode controller:
str="http://www.website.com/user-orders.php?e="+$scope.useremail;
$http.get(str)
.success(function (response){
$scope.user_orders = response;
sessionStorage.setItem('userorders_id', $scope.user_orders.id);
$scope.orders = [
{ id: $scope.user_orders.id,
uniqueid: $scope.user_orders.uniqueid,
platenumber: $scope.user_orders.platenumber,
paymentstatus: $scope.user_orders.paymentstatus,
orderstatus: $scope.user_orders.orderstatus
}
];
}).error(function() {
var alertPopup = $ionicPopup.alert({
title: 'Failed to get orders!',
template: 'Please check your credential'
});
});
Json:
{"records":{"id":"21","uniqueid":"42803122423","platenumber":"00000","paymentstatus":"Success","orderstatus":"Queued"},{"id":"22","uniqueid":"428032438","platenumber":"00000","paymentstatus":"Success","orderstatus":"Queued"},}
Template:
<ion-content ng-controller="orderslistCtrl">
<ion-list>
<ion-item ng-repeat="order in orders" href="#/app/orderslist/{{order.id}}">
{{order.id}}
{{order.uniqueid}}
</ion-item>
</ion-list>
</ion-content>
If i leave only 1 item in "records" as:
{"records":{"id":"21","uniqueid":"42803122423","platenumber":"00000","paymentstatus":"Success","orderstatus":"Queued"}}
it shows only 1 result. If I load two records it shows error.
Upvotes: 2
Views: 258
Reputation: 101
I think your json file was wrong...because your JSON object {records:{}} which contains records:{} as key as an object if you have n no.of record items you need to show inside an array as below
{"records":[{"id":"21","uniqueid":"42803122423","platenumber":"00000","paymentstatus":"Success","orderstatus":"Queued"},{{"id":"22","uniqueid":"428032438","platenumber":"00000","paymentstatus":"Success","orderstatus":"Queued"}}]}
Upvotes: 1