反序列化
public class CESHI { private string _name = ""; public string name { get { return _name; } set { _name = value; } } public List<JSTdatas> data { get; set; } } public class JSTdatas { private string _id = ""; /// <summary> /// 返回id /// </summary> public string id { get { return _id; } set { _id = value; } } } public class CESHIJSON { private string _name = ""; public string name { get { return _name; } set { _name = value; } } public JSTdatas data{ get; set; } }
string _resultcc = "{\"name\":\"武功\",data:[{\"id\":\"123\"}]}"; CESHI _cc = new JavaScriptSerializer().Deserialize<CESHI>(_resultcc); //解析JSON内容 string _name = _cc.name.ToString().Trim(); List<JSTdatas> _data = _cc.data; string _id = _data[0].id.ToString().Trim(); string _resultccj = "{\"name\":\"景观\",data:{\"id\":\"1488\"}}"; CESHIJSON _ccj = new JavaScriptSerializer().Deserialize<CESHIJSON>(_resultccj); //解析JSON内容 string _namej = _ccj.name.ToString().Trim(); JSTdatas _dataj = _ccj.data; string _idj = _dataj.id.ToString().Trim();
序列化:
https://www.cnblogs.com/shang201215019/p/7907655.html