3

I am trying to get a JSON object from a restful service. When I plug the URL into my browser (Firefox or Chrome) I receive the JSON with the proper UTF-8 encoding:

    {"name":"Université"}

However, when I attempt to GET the same URL in my Angular app, the text is not properly encoded. This is the object printed out from the JavaScript console:

    { name: "Universit�"}

Here is the code I'm using in Angular:

  $http(

      {
        method: "GET",
        url: 'localhost:8080/my/url/location',
        headers : {

          "Accept":"application/json;charset=utf-8",
          "Accept-Charset":"charset=utf-8"

        }
      }

  ).success(function(data,status,headers,config){

    console.log(data);

    /* the rest of the success function */ 

  }).error(function(data,status,headers,config){

    /* the rest of the failure function */ 

  });

Any ideas? Thanks ahead of time!

8
  • Do you get the same result when sending the get request without the headers? Commented Jul 29, 2015 at 15:38
  • Yes I do get the same results. Commented Jul 29, 2015 at 16:22
  • It seems like the problem could be related to the below previous question, are you sure the json file source is encoded in utf-8? stackoverflow.com/questions/20617117/… Commented Jul 29, 2015 at 16:35
  • That did the trick!! The JSON being sent by the server did not set the content type to application/json; charset=UTF-8. Thank you! Commented Jul 29, 2015 at 17:30
  • Being new to Stack Overflow, I'm not sure of the proper way to resolve this question. Do I answer my own question? Commented Jul 29, 2015 at 17:31

1 Answer 1

1

The problem was not with the code, but rather that the source file for the JSON was not being encoded in UTF-8

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.