我在 data/data.json 的本地文件夹中有 JSON 数据
{"category":"Soups","menu_item":"Tomato Soup","type":"veg"},{"category":"Starters","menu_item":"Summer Salad","type":"veg"},{"category":"Main Course","menu_item":"Black Beans Chicken","type":"non-veg"},{"category":"Soups","menu_item":"Lentil Soup","type":"veg"},{"category":"Starters","menu_item":"Roasted Root Veg","type":"veg"},{"category":"Starters","menu_item":"Herbed Chicken Wings","type":"non-veg"},{"category":"Main Course","menu_item":"Barbecue Chicken Sandwich","type":"non-veg"},{"category":"Main Course","menu_item":"Pasta with Sausage","type":"veg"},{"category":"Starters","menu_item":"Roasted Shallot, Beet, Spinach","type":"non-veg"},{"category":"Starters","menu_item":"Sauteed Broccoli","type":"veg"},{"category":"Soups","menu_item":"Chicken Soup","type":"non-veg"}
我想读这个,我想获取数据,我正在尝试这段代码,但我什么也没得到......
$.getJSON("data/data.json",
function (data) {
var i;
for (i=0; i<5; i++) {
$('<a href=""> <b>ITEM : </b>' + data.items[i].category +'</a><br>').appendTo(document.body);
}
});