'SyntaxError: Unexpected token o' with angularjs

This gives me an error when I try to call this controller.

hiren.controller('hirenz' , function($scope , $http , $location , $routeParams){
    $http.post((rootURL + "music") , {'alpha' : $routeParams.alpha , 'name' : $routeParams.name ,
        'album' : $routeParams.albumname }).success(function(data){
        var parsedJson = JSON.parse(data) ;
        console.log(parsedJson.name);
    });
});

Here is the "data" that I call from the server

{
    "name": [
        "Adhar - Adhar ",
        "Adhar - Adhare Opshori ",
        "Adhar - Aj Neshay "
    ],
    "url": [
        "http://music-com-bd.com/Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music.com.bd).mp3",
        "http://music-com-bd.com/Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music.com.bd).mp3",
        "http://music-com-bd.com/Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music.com.bd).mp3"
    ]
}
+4
source share
2 answers

You are parsing something that is not a string. It may already be in the form of a JSON object. You do not need to disassemble it. If you change var parsedJson = JSON.parse(data) ;to var parsedJson = data;Error will disappear.

+10
source

This error occurs when the JSON is malformed. Check it out with JSLint

+3
source

Source: https://habr.com/ru/post/1523327/


All Articles