JSON键中的特殊字符($)。getJson)

时间:2022-08-24 15:24:42

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

我遇到了这个问题:我试图将.json文件中的数据加载到我的站点中,但是我对标题中的特殊字符(O, i, E, space)有问题。我只能更改. html文件。这是。html: http://www.lukcian.x10.mx/json5.html

Thanks

谢谢

This is an example:

这是一个例子:

.json:

. json:

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

.html:

. 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

1 个解决方案

#1


1  

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

您正在尝试显示unicode字符。如果需要Unicode提供的额外字符,则需要更改字符集。

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

                                                   ^ change to charset=utf-8"

Reference: W3C Charset

参考:W3C字符集

#1


1  

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

您正在尝试显示unicode字符。如果需要Unicode提供的额外字符,则需要更改字符集。

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

                                                   ^ change to charset=utf-8"

Reference: W3C Charset

参考:W3C字符集