我试过这个但没有工作并得到错误SyntaxError:无效的属性id js小提琴链接http://jsfiddle.net/mm49u6wv/ var data={ { "Id": "12345", "Name": "Acme Widget 1", "Price": "£25.99", "Status": "In Stock" }, { "Id": "67890", "N
js小提琴链接http://jsfiddle.net/mm49u6wv/
var data={ { "Id": "12345", "Name": "Acme Widget 1", "Price": "£25.99", "Status": "In Stock" }, { "Id": "67890", "Name": "Acme Widget 2", "Price": "£28.99", "Status": "In Stock" }, { "Id": "11123", "Name": "Acme Widget 3", "Price": "£15.99", "Status": "In Stock" }, { "Id": "14156", "Name": "Acme Widget 4", "Price": "£33.99", "Status": "In Stock" } } $.each(data, function(i, v) { alert(v.id); });键区分大小写,因此id和Id不同.还要更正您的JSON数组.试试这个:
var data= [ { "Id": "12345", "Name": "Acme Widget 1", "Price": "£25.99", "Status": "In Stock" }, { "Id": "67890", "Name": "Acme Widget 2", "Price": "£28.99", "Status": "In Stock" }, { "Id": "11123", "Name": "Acme Widget 3", "Price": "£15.99", "Status": "In Stock" }, { "Id": "14156", "Name": "Acme Widget 4", "Price": "£33.99", "Status": "In Stock" } ]; $.each(data, function(i, v) { alert(v.Id); });
这是jsfiddle.