使用 AJAX 读取的语法错误 JSON 文件
Syntax Error JSON file read with AJAX
我的 JSON 文件中的方括号“[”出现语法错误。下面给出的是 JSON.
[
{
"Product Name":"CPE 10281",
"Application":"Tyres",
"Weight":150,
"Cost to Produce":5000,
"Grade":"A",
"Cost to Sell":40000,
"Strength":100
},
{
"Product Name":"CPE 10282",
"Application":"computers",
"Weight":250,
"Cost to Produce":4000,
"Grade":"H",
"Cost to Sell":25000,
"Strength":90
}
]
我正在尝试使用 AJAX 来读取我的 JSON 文件。
$.ajax({
url: "dataProductJSON.json",
dataType: 'json',
mimeType: "application/json",
success: function (data) {
var item = [];
$.each(data, function (key, val) {
item.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'interest-list',
html: item.join('')
}).appendTo('body');
},
});
我是 运行 我的 html 来自以 Apache Geronimo 作为服务器的 Eclipse。
请帮忙。
您在下面的行
中缺少一个 {
success: function (data)
成功
success: function (data) {
编辑
您对数据的解析有误,请按以下步骤操作
$.ajax({
url: "test.html",
dataType: 'json',
mimeType: "application/json",
success: function (data) {
var item = [];
$.each(data, function (key, val){
$.each(val, function (innerKey, innerValue){
item.push('<li id="' + innerKey + '">' + innerValue + '</li>');
});
});
$('<ul/>', {
'class': 'interest-list',
html: item.join('')
}).appendTo('body');
},
});
您需要使用 2 个循环,一个用于数组,另一个用于循环遍历对象 属性
我尝试了一些东西,它工作正常
我的 JSON 文件中的方括号“[”出现语法错误。下面给出的是 JSON.
[
{
"Product Name":"CPE 10281",
"Application":"Tyres",
"Weight":150,
"Cost to Produce":5000,
"Grade":"A",
"Cost to Sell":40000,
"Strength":100
},
{
"Product Name":"CPE 10282",
"Application":"computers",
"Weight":250,
"Cost to Produce":4000,
"Grade":"H",
"Cost to Sell":25000,
"Strength":90
}
]
我正在尝试使用 AJAX 来读取我的 JSON 文件。
$.ajax({
url: "dataProductJSON.json",
dataType: 'json',
mimeType: "application/json",
success: function (data) {
var item = [];
$.each(data, function (key, val) {
item.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'interest-list',
html: item.join('')
}).appendTo('body');
},
});
我是 运行 我的 html 来自以 Apache Geronimo 作为服务器的 Eclipse。 请帮忙。
您在下面的行
中缺少一个{
success: function (data)
成功
success: function (data) {
编辑
您对数据的解析有误,请按以下步骤操作
$.ajax({
url: "test.html",
dataType: 'json',
mimeType: "application/json",
success: function (data) {
var item = [];
$.each(data, function (key, val){
$.each(val, function (innerKey, innerValue){
item.push('<li id="' + innerKey + '">' + innerValue + '</li>');
});
});
$('<ul/>', {
'class': 'interest-list',
html: item.join('')
}).appendTo('body');
},
});
您需要使用 2 个循环,一个用于数组,另一个用于循环遍历对象 属性
我尝试了一些东西,它工作正常