8

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.

1 Answer 1

12

$http is serializing the data, so parse it before returning it JSON.parse(data)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.