簡體   English   中英

使用$ http解析JSON響應時出錯

[英]Error while parsing JSON response using $http

[
    {
        "dueAmount": 400,
        "paidAmount": 0,
        "balanceAmount": 400,
        "invoiceNo": "VA019_203829",
        "planName": null,
        "schemeName": null,
        "connectionStatus": null
    }
]

我收到郵遞員的回復。 但是,當我嘗試從我的頁面讀取這些內容時,它將返回“ Undefined

$http({ 
method:'POST', 
url: 'http://10.10.1.200:8081/SelfCare/customer/getInvoiceDetails',
headers: { 
            'Content-Type': 'application/json', 
            'Accept': 'application/json'
        }, 
data: JSON.stringify(getID)
       }).then(function (response) { 
        $scope.invoice = response.invoiceNo;
        alert($scope.invoice);
}

它總是警報未定義

您需要進行更改,替換$scope.invoice = response.invoiceNo; 通過$scope.invoice = response.data[0].invoiceNo;

您的響應將被封裝到data

采用

$scope.invoice = response.data[0].invoiceNo;

代替

$scope.invoice = response.invoiceNo;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM