TheOne LuKcian
TheOne LuKcian

Reputation: 89

Special characters in JSON key ( $.getJson )

i'm having this problem: I try to load data from a .json file to my site, but i'm havin problems with the special characters in the title ( Ó, Í, É , space ). I CAN ONLY CHANGE THE .HTML FILE. I have tryed This is the .html : http://www.lukcian.x10.mx/json5.html

Thanks

This is an example:

.json:

{
    "Bibliotecas": [
        {
            "BIBLIOTECA": "Biblioteca General de Navarra ",
            "DIRECCIÓN ": "Plaza de San Francisco",
            "COD. POSTAL": 31001,
            "POBLACIÓN": "Pamplona",
            "TELÉFONO": 848427797,
             .....................

.html:

<!DOCTYPE HTML> 
<html>
    <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">

    <title>JSON multiple zombies
    </title> 

    <script src="HostFiles/jquery.js"></script>
    <link href="reset.css" rel="stylesheet" type="text/css" media="screen">




    <script>


        $(document).ready(function() {
                 $.getJSON('json/bibliotecas.json', function(json) { 

                 $.each(json.Bibliotecas, function () {

                 $('<article class="json"></article>').append(

                 '<p> ' + this.BIBLIOTECA + '</p>'  + 
                 '<p> ' + this["DIRECCIÓN "] + '</p>' + 
                 '<p> ' + this.POBLACIÓN + '</p>' + 
                 '<p> ' + this.TELÉFONO + '</p>'  + 


                 '</br></br>'
                 ).appendTo('body');


    });          

  });

});





    </script>





</head> 
<body> 

</body>
    </html>

the result:

Biblioteca General de Navarra

undefined

undefined

undefined

Upvotes: 2

Views: 595

Answers (1)

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46748

You are trying to display unicode characters. If you require the extra characters offered by Unicode, you need to change charset.

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">

                                                   ^ change to charset=utf-8"

Reference: W3C Charset

Upvotes: 1

Related Questions