//简单JSON对象
function btn1_click()
{
var json = { "id": 1001, "name": "张三" };
document.getElementById("txtId").value = json.id;
document.getElementById("txtName").value = json.name;
}
//复合JSON对象
function btn2_click()
{
var json = { "id": 1001, "name": "张三", "phone": {"mobile":"13912345678","home":"66778899"} };
document.getElementById("txtId").value = json.id;
document.getElementById("txtName").value = json.name;
document.getElementById("txtMobile").value = json.phone.mobile;
document.getElementById("txtHome").value = json.phone.home;
}
//JSON对象数组
function btn3_click()
{
var array =
[
{ "id": 1001, "name": "张三", "phone":
{ "mobile": "13912345678", "home": "66778899" }
},
{ "id": 1002, "name": "李四", "phone":
{ "mobile": "1301122334", "home": "22334455" }
}
];
var json = array[1];
document.getElementById("txtId").value = json.id;
document.getElementById("txtName").value = json.name;
document.getElementById("txtMobile").value = json.phone.mobile;
document.getElementById("txtHome").value = json.phone.home;
}
var json = new
{
total = result.Tag,
rows = result.Result,
};
return Content(Common.JsonHelper.ToJson(json));
本文通过三个示例介绍了如何在JavaScript中操作不同类型的JSON数据,包括简单的JSON对象、复合JSON对象以及JSON对象数组。
105

被折叠的 条评论
为什么被折叠?



