javascript - Read a non JSON file in AngularJS -


the data in sakey-data.json file array of arrays.

[        [ 'brazil', 'portugal', 5 ],        [ 'brazil', 'france', 1 ],        [ 'brazil', 'spain', 1 ],        [ 'brazil', 'england', 1 ] ] 

i have been using factory service fetch data.

app.factory('sankeydata', ['$http', function($http){      return $http.get('http://localhost:4000/data/sakey-data.json')         .success(function(data){             return data;         })         .error(function(err){             return err;         });  }]); 

it unable data. rather shows error.

syntaxerror: unexpected token '

there no syntax error @ all. if change url actual json format file works well.

and can not change format of data in file because google graph api needs data in format.

please me find solution fetch such files server using angularjs.

as state @phylogenesis should replace ' ".
if that's not option, can configure $http transform response.

angular.module('app',[])    .controller('mainctrl', function(sankeydata) {     sankeydata.getdata().then(function(data) {       console.log(json.parse(data));     });   })    .factory('sankeydata', function($q, $http) {     var url = 'http://localhost:4000/data/sakey-data.json';     return {       getdata: function() {         return $http({            url: url,            transformresponse: function(response) {             return response.replace(/\'/g, '"');           },         }).then(function(response) {           return response.data;         });       }      };   }); 

imgur


Comments