gpt4 book ai didi

jquery - $.getJson 函数标题中有特殊字符

转载 作者:行者123 更新时间:2023-11-28 00:14:18 25 4
gpt4 key购买 nike

我遇到了这个问题:我尝试将数据从 .json 文件加载到我的站点,但我对标题中的特殊字符(Ó、Í、É、空格)有疑问。我只能更改 .HTML 文件这是一个例子:

.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>

结果:

Biblioteca General de Navarra

undefined

undefined

undefined

最佳答案

你应该使用 square bracket notation :

$.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>' +
// ...

关于jquery - $.getJson 函数标题中有特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13156618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com