JavaScript 处理 JSON 数据

$(function () {

//数据绑定开始

$.ajax({

type: "Post",

data: { startdate: "2012-4-1", enddate: "2012-4-29" },

url: "Normal/Service.aspx?Module=Sale_express_cost&Action=GetSaleExpressCost",

dataType: "json",

success: function (msg) {

//数据处理开始

var data = msg;

var html = JsonToHtml("单据号码", "快递物流公司", "快递单号码", "业务日期", "费用", "备注",

"付款状态", "录入者", "录入日期", "类型", "客户ID", "客户",

"业务员", "代收货款", "otype", "发货仓");

for (var i = 0; i < data.Head.length; i++) {

html += JsonToHtml(data.Head[0].orderid, data.Head[0].copid, data.Head[0].fno, data.Head[0].fdt, data.Head[0].feight_money, data.Head[0].f_memo,

data.Head[0].isfinish, data.Head[0].createby, data.Head[0].createdt, data.Head[0].sendtype, data.Head[0].customer_id, data.Head[0].realname,

data.Head[0].salesman, data.Head[0].prdt_money, data.Head[0].otype, data.Head[0].storage

);

}

//数据处理结束

$("#myGrid").html(html);

$(".myGridRow:first").addClass("myGridRowFirst");

}

});

//数据绑定结束

});

function JsonToHtml(orderid, copid, fno,fdt,feight_money,f_memo,

isfinish,createby,createdt,sendtype,customer_id,realname,

salesman,prdt_money,otype,storage) {

var resulthtml = "<div class=\"myGridRow\"><ul>";

resulthtml+="<li width:115px;\">"+orderid+"</li>";

resulthtml += "<li width:150px;\">" + copid + "</li>";

resulthtml += "<li width:115px;\">" + fno + "</li>";

resulthtml += "<li width:150px;\">" + fdt + "</li>";

resulthtml += "<li width:80px;\">" + feight_money + "</li>";

resulthtml += "<li width:300px;\">" + f_memo + "</li>";

resulthtml += "<li width:50px;\">" + isfinish + "</li>";

resulthtml += "<li width:80px;\">" + createby + "</li>";

resulthtml += "<li width:150px;\">" + createdt + "</li>";

resulthtml += "<li width:80px;\">" + sendtype + "</li>";

resulthtml += "<li width:100px;\">" + customer_id + "</li>";

resulthtml += "<li width:80px;\">" + realname + "</li>";

resulthtml += "<li width:80px;\">" + salesman + "</li>";

resulthtml += "<li width:80px;\">" + prdt_money + "</li>";

resulthtml += "<li width:50px;\">" + otype + "</li>";

resulthtml += "<li width:80px;\">" + storage + "</li>";

resulthtml = resulthtml + "</ul></div>";

return resulthtml;

}