jQuery.getJSON失败,语法错误
jQuery .getJSON failing, syntax error?
我正在尝试解析一个包含一些简单关键字的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"}后面有一个逗号,它不应该是最后一个元素。
数组的最后一个元素"操作系统"也会发生同样的情况。最后一个元素{"term","final"}后面不应该有逗号。
这是应该正确解析的代码:
{
"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未捕获语法错误意外的标识符错误
- 为什么忽略了eval()代码中的语法错误
- 难以访问的JS环境中的语法错误
- 未捕获的语法错误:意外的标记{
- "未捕获的语法错误:意外的标记}"
- 未捕获的语法错误:无法在“文档”上执行“查询选择器”
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- $(input[]).仅在firefox中出现每个抛出语法错误
- 为什么浏览器没有为语法错误抛出异常
- 错误:语法错误,无法识别的表达式:不支持的伪:无效/RectJS/Unit Testing
- 未捕获的语法错误:意外的令牌,
- jQuery.getJSON失败,语法错误
- "未捕获的语法错误:意外的标记"角度JS
- 参数列表Three.js之后的未捕获语法错误:缺少)
- 循环的Javascript冻结浏览器,没有语法错误
- 为什么匿名函数本身就是javascript中的语法错误
- 这怎么不是语法错误?这毫无意义!(javascript)
- 语法错误:缺少:在属性 ID 之后
- 未捕获错误:语法错误,无法识别的表达式:input[@type=submit]