0

我正在尝试解析一个包含一些简单关键词的 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"},
]}
4

1 回答 1

2

你确实有几个语法错误。

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

数组“操作系统”的最后一个元素也会发生同样的事情。最后一个元素 {"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"}
]}
于 2012-09-10T00:22:34.453 回答