这是前台别人传给我的数据:[["3/17/2012",[[0,0],[0,0],[0,0],[0,0],[0,0]],200]]
这里面的每个数据都有一个对应的字段(有一个model文件),这个我要怎么转换啊!!!
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
这12个数据和下面的类成员的对应关系是什么?
知道对应关系的话,可以解析json字符串后,对它们进行赋值,比如:
- C# code
static void Main(string[] args){ string json = "[[\"3/17/2012\",[[0,0],[0,0],[0,0],[0,0],[0,0]],200]]"; var jss = new JavaScriptSerializer(); var data = jss.Deserialize<dynamic>(json); var d = data[0]; var m = new Model(); m.p_OutTime = Convert.ToDateTime(d[0]); m.p_SingleRoomPrice = d[1][0][0]; m.p_SingleRoomSum = d[1][0][1]; m.p_ParRoomPrice = d[1][1][0]; m.p_ParRoomSum = d[1][1][1]; m.p_AdminRoomPrice = d[1][2][0]; m.p_AdminRoomSum = d[1][2][1]; m.p_LuxuryRoomPrice = d[1][3][0]; m.p_LuxuryRoomSum = d[1][3][1]; m.p_PresRoomPrice = d[1][4][0]; m.p_PresRoomSum = d[1][4][1]; m.p_CountRomm = d[2];}class Model{ public decimal p_SingleRoomPrice { get; set; } public int p_SingleRoomSum { get; set; } public decimal p_ParRoomPrice { get; set; } public int p_ParRoomSum { get; set; } public decimal p_AdminRoomPrice { get; set; } public int p_AdminRoomSum { get; set; } public decimal p_LuxuryRoomPrice { get; set; } public int p_LuxuryRoomSum { get; set; } public decimal p_PresRoomPrice { get; set; } public int p_PresRoomSum { get; set; } public DateTime p_OutTime { get; set; } public int p_CountRomm { get; set; }}
------解决方案--------------------------------------------------------
这个都不是标准的JSON数据,要么就是按照规律来找,要么正则吧。