简体   繁体   中英

Angularjs $http.get returning JSON data as a string with escaped quotes instead of json

Interesting problem here. I have restful backend that returns JSON. When I access the api through the browser it returns a validated json array with a json object.

[{"GUID_Auth":null,"Email_Address":"abc@aol,"Measure_Id":1,"Title":"Prop 41"}]

but when I make a $http.get request through angularjs I instead get back a string with escaped quotes

got success: "[{\\"GUID_Auth\\":null,\\"Email_Address\\":\\"abc@aol\\",\\"Measure_Id\\":1,\\"Title\\":\\"Prop 41\\"}]"

Here is a snippet of my angularjs controller code

.controller('MainCtrl', function($scope,$http) {
  $scope.GetData = function(){
    var responsePromise = $http.get('http://backend.api');
    responsePromise.success(function(data,status,headers,config){
      console.log('got success: ' + data);
      console.log('test'+ data[0].Email_Address)
    });
    responsePromise.error(function(data,status,headers,config){
      alert('ajax failed');
    });
  },

This is very perplexing any help would be greatly appreciated.

$ http正在序列化数据,因此在返回它之前解析它JSON.parse(data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM