phpjsonunicode

JSON response, how to decode characters with accent?


I am receiving a JSON response from a webservice so the character Ô turns into \u00d3

How can PETR\u00d3POLIS become PETRÓPOLIS?

I am using PHP to query the database and return JSON.

After a research from http://www.fileformat.info/info/unicode/char/00d3/index.htm I know the character is Unicode Character 'LATIN CAPITAL LETTER O WITH ACUTE' (U+00D3) .

Which is the best way to translate these characters?


Solution

  • Unicode characters are just like escape characters - you can see them in JS string, but they will be displayed properly as a text.

    var o = {
      text: 'PETR\u00d3POLIS  \n\u00a5\u00a5\u00a5'
    };
    
    document.body.innerHTML = "<pre>" + o.text + "</pre>";