最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - 'SyntaxError: Unexpected token o' with angularjs - Stack Overflow

programmeradmin3浏览0评论

It gaves me error when I m trying 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 am calling from server

{
    "name": [
        "Adhar - Adhar ",
        "Adhar - Adhare Opshori ",
        "Adhar - Aj Neshay "
    ],
    "url": [
        " Opshori/Adhar - Adhar (music.bd).mp3",
        " Opshori/Adhar - Adhar (music.bd).mp3",
        " Opshori/Adhar - Adhar (music.bd).mp3"
    ]
}

It gaves me error when I m trying 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 am calling from server

{
    "name": [
        "Adhar - Adhar ",
        "Adhar - Adhare Opshori ",
        "Adhar - Aj Neshay "
    ],
    "url": [
        "http://music--bd./Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music..bd).mp3",
        "http://music--bd./Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music..bd).mp3",
        "http://music--bd./Music/A/Adhar/Adhare Opshori/Adhar - Adhar (music..bd).mp3"
    ]
}
Share Improve this question asked Jan 23, 2014 at 12:13 pyprismpyprism 3,00810 gold badges52 silver badges85 bronze badges 1
  • 'SyntaxError: Unexpected token o' – pyprism Commented Jan 23, 2014 at 12:17
Add a ment  | 

2 Answers 2

Reset to default 10

You are parsing something which is not a string. It might be already in form of JSON object. You do not need to parse it. If you change var parsedJson = JSON.parse(data) ; to var parsedJson = data; The error will go off.

This error occurs when JSON is not properly formed. Check it with JSLint

发布评论

评论列表(0)

  1. 暂无评论