{
JsonResult json = new JsonResult
{
Data = new
{
Name = "zzl",
Sex = "male",
}
};
return Json(json);
}
public JsonResult TestList()
{
ListuserList = new List
{
new User{Name="zzl",Email="[email protected]"},
new User{Name="zhz",Email="[email protected]"},
};
JsonResult json = new JsonResult
{
Data = userList
};
return Json(json);
//return Json(json, JsonRequestBehavior.AllowGet);//前台AJAX如果是GET用这句//什么时候用GET请求呢,当我们直接在浏览器中输入网址时,其实就是一个GET请求//如果我们直接输入/Home/TestList这个网址,它会提示我们下载这个JSON格式的文档
}
{
ListuserList = new List
{
new User{Name="zzl",Email="[email protected]"},
new User{Name="zhz",Email="[email protected]"},
new User{Name="zql",Email="[email protected]"},
};
return Json(userList);
}
url: "/Home/TestList",
dataType: "json",
cache: false,
data: null,
type: "POST",
success: function (data) {
var msg = "
Name | |
" + data[i].Name + " | "
+ data[i].Email + " |
";
$("#msg2").html(msg);
}
});
var arr = [{ "name": "zzl", "sex": "男" }, { "name": "lr", "sex": "女"}];
for (var i = 0; i < arr.length;i++ ) {
document.write(arr[i].name);
}