简体   繁体   中英

Unexpected SyntaxError: Unexpected token : from JSON data (AngularJS Api Request)

So I'm getting this error and when I click on the link it shows next to it, it takes me to some json response:

{"link-canonical":"https:\/\/myanimelist.net\/anime\/1\/Cowboy_Bebop",.....}

I'm simply making a get request for an anime api. Apparently this colon in the json it retrieves is giving me the error..? I have no idea. My code for the request is definitely working but I just tried it out with another api url which worked fine.

This is the code for the request:

myApp.controller('mainController', ['$scope', '$resource', function($scope, $resource) {

$scope.animeApi = $resource('http://jikan.me/api/anime/1', {callback: "JSON_CALLBACK"}, { get: { method: "JSONP" }});

$scope.animeResult = $scope.animeApi.get({});
console.log($scope.animeResult);

}]);

So you know what to do:

let str = {"link-canonical":"https:\/\/myanimelist.net\/anime\/1\/Cowboy_Bebop"};
let data = JSON.parse(JSON.stringify(str));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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