gpt4 book ai didi

javascript - JS 中输入意外结束

转载 作者:行者123 更新时间:2023-12-02 18:36:46 27 4
gpt4 key购买 nike

我正在尝试通过 javaScript 加载 JSON 文件。我在 HTML 中放置了执行函数 loadAJAX 的按钮。但我在第 11 行 var items = JSON.parse(request.responseText); 上不断收到错误上面写着unexpected end of input 。我已经检查了好几次,但找不到解决方案。 Test SITE

script.js

function loadAJAX() {
var request;
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
} else {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("GET", "data.json");
request.onreadystatechange = function (){
if((request.status === 200) && (request.readyState === 4)){
var items = JSON.parse(request.responseText);
var output = "<ul>";
for (var key in items){
output += "<li>" + items[key].colorName + "</li>";
}
output += "</ul>";
document.getElementById("update").innerHTML = output;


}
};
request.send();
}

数据.json

  {
"colorsArray":[{
"colorName":"red",
"hexValue":"#f00",
"info" : "My favorite color."
},
{
"colorName":"green",
"hexValue":"#0f0",
"info" : "Old color for old things, like food ew."

},
{
"colorName":"blue",
"hexValue":"#00f",
"info" : "Reminds me of bruised arm."
},
{
"colorName":"cyan",
"hexValue":"#0ff",
"info" : "Not an idea what color this is."
},
{
"colorName":"magenta",
"hexValue":"#f0f",
"info" : "Every girl talks about her color being this."
},
{
"colorName":"yellow",
"hexValue":"#ff0",
""info" : "My mom likes yellow."
},
{
"colorName":"black",
"hexValue":"#000",
"info" : "Well now look at this color the new white lol."
}
]
}

最佳答案

“信息:旧事物的旧颜色,例如食物。”

您不小心在这里引用了整行内容。对象属性的名称和值需要单独引用。重写为

"info": "旧事物的旧颜色,比如食物。"

这还会进一步掩盖重复的引号字符:

""info": "我妈妈喜欢黄色。"

键名info前面只能有一个。

关于javascript - JS 中输入意外结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17246707/

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