1
我有一個JSON文件沒有數組名稱的JSON數組?
{
"info":[
{
"Name":"Noob Here1",
"Department":"Language",
"Sex":"Male",
"Basic_Salary":"175",
"ESI":"58",
"Employee_PF":"60.50",
"Bonus":"2.60"
},
{
"Name":"Noob Here2",
"Department":"Employee_PF",
"Sex":"Female",
"Basic_Salary":"10.5",
"ESI":"4.0",
"Employee_PF":"20",
"Bonus":"0.5"
},
{
"Name":"Noob Here3",
"Department":"Physics",
"Sex":"Male",
"Basic_Salary":"165",
"ESI":"55",
"Employee_PF":"875",
"Bonus":"200"
}
]
}
我使用的getJSON
loadData(myFile).done(function (data1) {
// check if we acutally get something back and if the data has the info property
if (data1 && data1.info) {
data = data1;
var html = "";
var head = "";
$.each(data1.info[0], function (key, value) {
html += "<td><input data-bind='value:" + key + "'></td>";
head += "<th>" + key + "</th>";
});
html += "<td><input data-bind='value: result'/></td>";
head += "<th>Result</th>";
$("#div1 thead").append(head);
$("#div1").append("<tr></tr>");
$("#div1 tr").append(html);
}
});
注意採取從它的數據:MYFILE屬性給出JSON文件的名稱
和將數據追加到DOM
我可以使用像
一個JSON{
[
{
"Name":"Noob Here1",
"Department":"Language",
"Sex":"Male",
"Basic_Salary":"175",
"ESI":"58",
"Employee_PF":"60.50",
"Bonus":"2.60"
},
{
"Name":"Noob Here2",
"Department":"Employee_PF",
"Sex":"Female",
"Basic_Salary":"10.5",
"ESI":"4.0",
"Employee_PF":"20",
"Bonus":"0.5"
},
{
"Name":"Noob Here3",
"Department":"Physics",
"Sex":"Male",
"Basic_Salary":"165",
"ESI":"55",
"Employee_PF":"875",
"Bonus":"200"
}
]
}
如果是如何稱呼呢?
數據1 [0] [0]給出菜鳥here1 – Tyranicangel 2013-04-04 12:38:00
刪除。信息和數據來做,這是 – 1Mayur 2013-04-04 12:38:13
到這裏看看: http://stackoverflow.com/questions/6964387/how-to-parse-json-array-with-no-object-name – 2013-04-04 12:38:13