mui post json 格式数据

客户端:

var url="http://www.baidu.com/appinterface.aspx?action=subcheckdata";
var data="";
var type="post";
var dataType="json";
data+="{";
data+="\"company\":\""+cid+"\",";
data+="\"userid\":\""+plid+"\",";
data+="\"reason\":\"\",";
data+="\"lat\":\""+lat+"\",";
data+="\"longt\":\""+longt+"\",";
data+="\"checklist\":[";
$("input[type=checkbox]").each(function () { 
	data += "{\"id\":\"" + $(this).attr("id") + "\",";
	if ($(this).attr("checked") != undefined) {
		data += "\"value\":\"1\"},";
	}
	else {
		data += "\"value\":\"0\"},";
	}
});
data = data.substr(0, data.length - 1);
data+="]";
data+="}";
//$("#dtest").html(data);
$.post(url, data, postsuccess, dataType);

var postsuccess = function(response) {
//response = JSON.stringify(response);
//alert(response.success);
//console.log(response);
if(response.success)
{
	mui.toast("保存成功");
	mui.back();
}
else{
	mui.toast(response.error);
}
};

服务器端取值:

byte[] byts = new byte[Request.InputStream.Length];
Request.InputStream.Read(byts, 0, byts.Length);
string req = System.Text.Encoding.UTF8.GetString(byts);
maindata data = JsonHelper.ParseFormJson(req);//格式化为类
string reason = data.reason;//第一级属性直接取值
List list_check = data.checklist;//带有子集的使用泛型
checkmodel mcheck = list_check[j];//第j个对象为实体类
mcheck.id//又是直接取值
//下边是和上边对应的类的申明 
public class checkmodel
{
	public string id { get; set; }
	public string value { get; set; }
}
public class maindata
{
	public string company { get; set; }
	public string userid { get; set; }
	public string reason { get; set; }
	public string lat { get; set; }
	public string longt { get; set; }
	public List checklist { get; set; }
	public maindata()
	{
		checklist = new List();
	}

}

你可能感兴趣的:(MUI)