String转集合

 

eg:["国际级","国家级","区域级","城市级"]

 if (!string.IsNullOrWhiteSpace(Level))
 {
   list = Common.JsonHelper.JsonDeserialize<List<string>>(Level);

 }

 接口返回的数据:

 

方法:

     /// <summary> /// .net自带 JSON反序列化 /// </summary> public static T JsonDeserialize<T>(string jsonString) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); T obj = (T)ser.ReadObject(ms); return obj; }

  

posted @ 2023-01-09 18:13  小易儿  阅读(108)  评论(0编辑  收藏  举报