我有JSON文件:
{
"name": "sami",
"desig":"Employee"
"location": "Pune",
},
{
"name": "joshaph",
"desig":"Employee"
"location": "Delhi",
},
{
"name": "mani",
"desig":"Employee"
"location": "Kolkatha",
},
{
"name": "Ravi",
"desig":"Manager"
"location": "Pune",
}
{
"name": "Harthick",
"desig":"Manager"
"location": "Delhi",
}
而且,我编写了以下代码来检索json文件,
function fetchDataForJSON(callback) {
var _url = "myURL";
$.ajax({
url: _url,
type: "GET",
cache: false,
contentType: "application/javascript",
dataType: "json",
success: function (data) {
result = JSON.parse(JSON.stringify(data).replace(/'/g, ''));
callback(result);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
console.log(jqXHR.status);
}
});
}
function displayDetails(result){
var jsonObj = { ... }
}
我想在HTML页面中显示它。它应该按设计分类。任何人都可以帮助我编写用于显示详细信息的javascript代码。
我的结果应该显示在HTML页面中,使用JavaScript,在“雇员”类别下的前三个成员,在“经理”类别下,最后三个成员。
答案 0 :(得分:1)
您想念逗号!
{
"name": "sami",
"desig":"Employee",
"location": "Pune",
},
{
"name": "joshaph",
"desig":"Employee",
"location": "Delhi",
},
{
"name": "mani",
"desig":"Employee",
"location": "Kolkatha",
},
{
"name": "Ravi",
"desig":"Manager",
"location": "Pune",
}
{
"name": "Harthick",
"desig":"Manager",
"location": "Delhi",
}
success: function (data) {
for (var i = 0; i < data.length; i++) {
var l = data[i];
$("#....").val(l["name"]);
$("#....").val(l["desig"]);
$("#....").val(l["location"]);
}
},