2017-07-27 67 views
-1

我建立在ASP一個HTTP POST網頁API,以JSON返回以下字符串網頁API Invaild JSON結果通過角JS

RootObject rootObject = new RootObject() 
{ 
    status = "User Registered" 
}; 

    msg = JsonConvert.SerializeObject(rootObject); 

下面是我的角度JS控制器在我消費,網頁API

.controller('signupCtrl', function($scope,$http,$ionicPopup,$state,$ionicHistory) { 

$scope.signup=function(data){ 

    var link = 'http://xxxxxxxxxxxxxxxxxxxxxx/api/Home/RegisterUser'; 

    //using http post 
    //passing values to parameter 
    $http.post(link, {RegisterName : data.name, RegisterUserName : data.username, RegisterPassword : data.password , RegisterEmail: data.mail , RegisterMobile : data.mobile}) 
    .then(function (res){ //if a response is recieved from the server. 

     $scope.response = res; //contains Register Result 

     console.log($scope.response); 
    }); 
    } 
}) 

與上面的代碼我得到下面的結果在谷歌瀏覽器的控制檯

With the above code I am getting following result in google chrome console

我嘗試獲取該狀態只是爲了匹配它的值,但我無法這樣做。 我的疑問是,json格式

+0

只希望'status' JSON.parse(res.data)或$ .parseJSON(res.data)..我是正確的? –

+0

您可以通過輕鬆訪問結果中的數據對象來訪問狀態值。這裏有什麼問題 ? –

+0

那麼問題是什麼?你可以訪問你的** Object **中的'data'字符串,然後將其解析爲Json。 –

回答

0

console.log(JSON.stringify($scope.response))會做你所需要的。

如果你想要這些特定的值,你可以訪問這些值並將它們傳遞給日誌。

console.log($scope.response.data['status']); 
0

你得到的JSON爲:

$ scope.response = res.data;

可能是你需要獲得JSON對象