1
我必須將xml response to json
轉換爲angularjs
。我使用的是一個Rest api,它以xml格式提供響應,但是當通過$ http.get()獲取時,angularjs需要json響應。使用angularjs從數據庫檢索記錄後,將xml轉換爲json
以下是我如何在angularjs中使用rest api。
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$http) {
$http({
method: 'GET',
url: "https://some-url?fieldList=field1,field2"
}).then(function(response) {
$scope.obj=response.data.records;},function(response){});}
});
</scripts>
如何將xml響應轉換爲json並將其作爲輸入提供給某個變量$ scope.obj?