javascript 传来 c# var json = context.Request["json"]; Dictionary<string, object> obj = jss.Deserialize<Dictionary<string, object>>(json); string check_in = obj["check_in"].ToString(); string check_out = obj["check_out"].ToString(); string discount_rate = obj["discount_rate"].ToString(); double total_all_room_price_from_client = Convert.ToDouble(obj["total_all_room_price"]); client_select 该怎么获取呢? public class Handler_client_select { public int how_much_room { get; set; } public ArrayList additional_chop_id_list { get; set; } } 暂时用的方法是js 序列化多一次,然后c# 反序列化多一次 |
|
一步一步序列化
比如先序列化成hashtable var obj=(System.Collections.Hashtable)Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(System.Collections.Hashtable)); 然后 var clientSelectJson= obj[“client_select”].ToString();再进一步序列化成hashtable获取值 |
|
10分 |
用LitJSON不行吗?
|
序列化为json数组
|
|
感谢,这个不错。 //var obj = { // person: { list: [1, 2, 3] }, // animal: [{ name: "keatkeat" }, {name:"xinyao"}], // }; string json = hd.Value; JsonData data = JsonMapper.ToObject(json); var keys = (data as IDictionary).Keys; foreach (string attr in keys) { //有方法转换吗? List<animal> animal_list = (List<animal>)data["animal"]; Dictionary<string, ArrayList> person = (Dictionary<string, ArrayList>)data["person"]; } |
|
使用newtonjson 很容易满足LZ的需求
|
|
10分 |
http://www.cnblogs.com/usharei/archive/2012/04/24/2467578.html 附个入门教程
|