mona la mona la - 5 months ago 18
AngularJS Question

angular.js:13708 SyntaxError: Unexpected token p in JSON at position 130

this is my controller in angularjs



(function(){
"use strict";
angular
.module("testApp")
.controller("testAppCtrl", function($scope , $http){
$http.get('/data/testapp.json').then(function(data){
//$scope.testapps = testapp.data;
console.log(data);
});
});
})();





and i face this error

angular.js:13708 SyntaxError: Unexpected token p in JSON at position 130


how can i fix it?
and the json file http://monala.ir/testapp.json

Answer

Your json file has invalid code.You are missing quots around posted and contact also in the and extra , is inserted this should be like

[{
"id": "1",
"title": "test1",
"description": "test 1 test 1 test 1 test 1 test 1 ",
"price": "2000",
"posted": "2015-10-24",
"contact": {
    "name": "test1 mona",
    "phone": "98765678",
    "email": "test@gmail.com"
},
"categories": [
    "vehicle",
    "test"
],
"image": "1.jpg",
"views": "200"
}, {
"id": "2",
"title": "test2",
"description": "test 2 test 2 test 2 test 2 test 2 ",
"price": "2000",
"posted": "2015-10-24",
"contact": {
    "name": "test2 mona",
    "phone": "98765678",
    "email": "test@gmail.com"
},
"categories": [
    "vehicle",
    "test"
],
"image": "1.jpg",
"views": "200"
}, {
"id": "3",
"title": "test3",
"description": "test 3 test 3 test 3 test 3 test 3 ",
"price": "3000",
"posted": "2015-10-24",
"contact": {
    "name": "test3 mona",
    "phone": "98765678",
    "email": "test@gmail.com"
},
"categories": [
    "vehicle",
    "test"
],
"image": "1.jpg",
"views": "100"
}, {
"id": "4",
"title": "test4",
"description": "test 4 test 4 test 4 test 4 test 4 ",
"price": "4000",
"posted": "2015-10-24",
"contact": {
    "name": "test4 mona",
    "phone": "98765678",
    "email": "test@gmail.com"
},
"categories": [
    "vehicle",
    "test"
],
"image": "1.jpg",
"views": "40"
}, {
"id": "5",
"title": "test5",
"description": "test 5 test 5 test 5 test 5 test 5 ",
"price": "5000",
"posted": "2015-10-24",
"contact": {
    "name": "test5 mona",
    "phone": "98765678",
    "email": "test@gmail.com"
},
"categories": [
    "vehicle",
    "test"
],
"image": "1.jpg",
"views": "290"
}, {
"id": "6",
"title": "test6",
"description": "test 6 test 6 test 6 test 6 test 6 ",
"price": "6000",
"posted": "2015-10-24",
"contact": {
    "name": "test6 mona",
    "phone": "98765678",
    "email": "test@gmail.com"
},
"categories": [
    "vehicle",
    "test"
],
"image": "1.jpg",
"views": "10"
}]