JSON数组成员反序列化

场景:

构想客户端能够传递如下格式JSON字符串到服务端:

{"KeyValueSetList":[{"SN":"RQ1001","KeyValueList":[{"Key":"money","Value":"1000","Encode":0}]},{"SN":"RQ1002","KeyValueList":[{"Key":"money","Value":"2000","Encode":0}]}]}

分析:

这是一个拥有数组成员对象的JSON字符串

服务端针对JSON格式创建相应对象

public class KeyValue
    {
        public string Key { get; set; }
        public string Value { get; set; }
        public int Encode { get; set; }
        //public Dictionary<string,object> ToDictionary(List<KeyValue>)
    }
    public class KeyValueSet {
        public List<KeyValue> KeyValueList { get; set; }
        public string SN { get; set; }    
    }
    public class KeyValueSetWrap
    {
        public List<KeyValueSet> KeyValueSetList { get; set; }
    }

///Newtonsoft反射

 public static  T Deserialize<T>(string json)
    {
        T t= JsonConvert.DeserializeObject<T>(json);

        return t;

  }

posted @ 2016-05-07 09:50  jeffery1010  Views(502)  Comments(0Edit  收藏  举报