我已多次这样做,但出于某种原因,这次没有用。
我正在编译一个对象列表,将它们序列化为json并将它们返回到我的页面进行显示。
foreach (var rec in results)
{
clientsout.Add(new Clients
{
Forename = rec.Forename,
Surname = rec.Surname,
HouseNameNum = rec.HouseNameNum,
StreetRoad = rec.StreetRoad,
Area = rec.Area,
PostCode = rec.PostCode,
HomeTel = rec.HomeTel,
Mobile = rec.Mobile,
WorkTel = rec.WorkTel,
EmailAddress = rec.EmailAddress
});
}
var json = JsonConvert.SerializeObject(clientsout);
return json;
然后我在我的javascript中有一个函数'应该'循环遍历每条记录并根据我得到的结果创建html:
for (var i = 0; i < data.length; i++ ){
var tr = $('i wont bore you with the html');
$('#clientstable').append(tr);
}
由于某种原因,我似乎无法访问数据,它返回如下:
[{"Id":0,"Forename":"K","Surname":"M","HouseNameNum":"3","StreetRoad":"M Road","Area":"H","PostCode":"Postcode Here","HomeTel":111123456,"Mobile":1111,"WorkTel":1111000,"EmailAddress":"someoney@gmail.com","ClientType":null,"TraderId":null},{"Id":0,"Forename":"Kelly","Surname":"SOmeone","HouseNameNum":"87","StreetRoad":"asdlasdkj","Area":"lkjlk","PostCode":"lkjljk","HomeTel":987987,"Mobile":979879,"WorkTel":987978,"EmailAddress":"987987","ClientType":null,"TraderId":null}]
我通常会通过data [i] .Forename等等访问数组中的每条记录
它可能会非常简单,但我在哪里出错?
我使用了相同的方法加载次数