场景:

构想客户端能够传递如下格式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;

  }

相关文章:

  • 2021-06-04
  • 2021-12-10
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2021-08-30
  • 2021-10-29
猜你喜欢
  • 2021-11-23
  • 2021-11-29
  • 2021-10-24
  • 2022-01-12
  • 2022-01-26
  • 2022-12-23
相关资源
相似解决方案