gpt4 book ai didi

javascript - jQuery .getJSON 失败,语法错误?

转载 作者:行者123 更新时间:2023-12-02 19:22:44 24 4
gpt4 key购买 nike

我正在尝试解析包含一些简单关键字的 JSON 文件。我的函数没有运行。查看 jQuery .getJSON 文档,我意识到最可能的解释是语法错误。我已经非常彻底地查看了我的代码,但我今天才学习了 JSON。谁能帮我吗?抱歉,我知道数据量很大。

JavaScript 代码:

$(document).ready(function() {
$.getJSON('edit/key.json', function(data2) {
console.log(data2);
//more code
});

});

JSON 代码:

{
"RAM": [
{"term" : "ram"},
{"term" : "memory"},
{"term" : "access"},
{"term" : "random"},
{"term" : "component"},
{"term" : "multi-tasking"},
{"term" : "multi"},
{"term" : "tasking"},
{"term" : "gigabyte"},
{"term" : "temporary"}
],
"Graphics Card": [
{"term" : "component"},
{"term" : "graphic"},
{"term" : "graphics card"},
{"term" : "processing"},
{"term" : "processors"},
{"term" : "unit"},
{"term" : "card"},
{"term" : "3D"},
{"term" : "image"},
{"term" : "media"},
{"term" : "gaming"},
{"term" : "game"},
{"term" : "nvidia"},
{"term" : "amd"},
{"term" : "chip"},
{"term" : "clock"},
{"term" : "speed"},
{"term" : "GPU"},
{"term" : "video"},
{"term" : "DVI"},
{"term" : "DisplayPort"},
{"term" : "HDMI"}
],
"Ports": [
{"term" : "port"},
{"term" : "interface"},
{"term" : "external"},
{"term" : "USB"},
{"term" : "devices"},
{"term" : "3.0"},
{"term" : "2.0"},
{"term" : "VGA"},
{"term" : "DVI"},
{"term" : "HDMI"},
{"term" : "display"},
{"term" : "port"},
{"term" : "memory"},
{"term" : "card"},
{"term" : "SD"},
{"term" : "stick"},
{"term" : "ethernet"},
{"term" : "input"},
{"term" : "output"},
],
"CPU": [
{"term" : "cpu"},
{"term" : "central"},
{"term" : "processing"},
{"term" : "unit"},
{"term" : "computing"},
{"term" : "compute"},
{"term" : "intel"},
{"term" : "AMD"},
{"term" : "processors"},
{"term" : "desktop"},
{"term" : "laptop"},
{"term" : "i3"},
{"term" : "i5"},
{"term" : "i7"},
{"term" : "core"},
{"term" : "turbo"},
{"term" : "boost"},
{"term" : "gaming"},
{"term" : "media"},
{"term" : "overclocked"},
{"term" : "clock"},
{"term" : "speed"}
],
"Hard Drive": [
{"term" : "store"},
{"term" : "data"},
{"term" : "hard"},
{"term" : "drive"},
{"term" : "video"},
{"term" : "music"},
{"term" : "picture"},
{"term" : "document"},
{"term" : "media"},
{"term" : "processor"},
{"term" : "gigabyte"},
{"term" : "terabyte"},
{"term" : "rpm"},
{"term" : "cache"}
],
"Operating System": [
{"term" : "operating"},
{"term" : "system"},
{"term" : "os"},
{"term" : "device"},
{"term" : "windows"},
{"term" : "mac"},
{"term" : "linux"},
{"term" : "ubuntu"},
{"term" : "chrome"},
{"term" : "xp"},
{"term" : "vista"},
{"term" : "7"},
{"term" : "8"},
{"term" : "home"},
{"term" : "premium"},
{"term" : "professional"},
{"term" : "ultimate"},
]}

最佳答案

您确实有几个语法错误。

端口数组中有一个额外的逗号。 {"term": "output"} 后面有一个逗号,但它不应该是最后一个元素。

数组“Operating System”的最后一个元素也会发生同样的情况。最后一个元素 {"term", "ultimate"} 后面不应有逗号。

这是正确的代码,应该可以很好地解析:

{
"RAM": [
{"term" : "ram"},
{"term" : "memory"},
{"term" : "access"},
{"term" : "random"},
{"term" : "component"},
{"term" : "multi-tasking"},
{"term" : "multi"},
{"term" : "tasking"},
{"term" : "gigabyte"},
{"term" : "temporary"}
],
"Graphics Card": [
{"term" : "component"},
{"term" : "graphic"},
{"term" : "graphics card"},
{"term" : "processing"},
{"term" : "processors"},
{"term" : "unit"},
{"term" : "card"},
{"term" : "3D"},
{"term" : "image"},
{"term" : "media"},
{"term" : "gaming"},
{"term" : "game"},
{"term" : "nvidia"},
{"term" : "amd"},
{"term" : "chip"},
{"term" : "clock"},
{"term" : "speed"},
{"term" : "GPU"},
{"term" : "video"},
{"term" : "DVI"},
{"term" : "DisplayPort"},
{"term" : "HDMI"}
],
"Ports": [
{"term" : "port"},
{"term" : "interface"},
{"term" : "external"},
{"term" : "USB"},
{"term" : "devices"},
{"term" : "3.0"},
{"term" : "2.0"},
{"term" : "VGA"},
{"term" : "DVI"},
{"term" : "HDMI"},
{"term" : "display"},
{"term" : "port"},
{"term" : "memory"},
{"term" : "card"},
{"term" : "SD"},
{"term" : "stick"},
{"term" : "ethernet"},
{"term" : "input"},
{"term" : "output"}
],
"CPU": [
{"term" : "cpu"},
{"term" : "central"},
{"term" : "processing"},
{"term" : "unit"},
{"term" : "computing"},
{"term" : "compute"},
{"term" : "intel"},
{"term" : "AMD"},
{"term" : "processors"},
{"term" : "desktop"},
{"term" : "laptop"},
{"term" : "i3"},
{"term" : "i5"},
{"term" : "i7"},
{"term" : "core"},
{"term" : "turbo"},
{"term" : "boost"},
{"term" : "gaming"},
{"term" : "media"},
{"term" : "overclocked"},
{"term" : "clock"},
{"term" : "speed"}
],
"Hard Drive": [
{"term" : "store"},
{"term" : "data"},
{"term" : "hard"},
{"term" : "drive"},
{"term" : "video"},
{"term" : "music"},
{"term" : "picture"},
{"term" : "document"},
{"term" : "media"},
{"term" : "processor"},
{"term" : "gigabyte"},
{"term" : "terabyte"},
{"term" : "rpm"},
{"term" : "cache"}
],
"Operating System": [
{"term" : "operating"},
{"term" : "system"},
{"term" : "os"},
{"term" : "device"},
{"term" : "windows"},
{"term" : "mac"},
{"term" : "linux"},
{"term" : "ubuntu"},
{"term" : "chrome"},
{"term" : "xp"},
{"term" : "vista"},
{"term" : "7"},
{"term" : "8"},
{"term" : "home"},
{"term" : "premium"},
{"term" : "professional"},
{"term" : "ultimate"}
]}

关于javascript - jQuery .getJSON 失败,语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12344059/

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