我正在尝试解析包含一些简单关键字的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"},
]}
答案 0 :(得分:2)
你确实有几个语法错误。
ports数组中有一个额外的逗号。 {“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"}
]}