json格式字符串处理

时间:2021-03-25 12:35:53
public class InternalClass
        {
            public int MID;
            public string Name;
            public string Des;
            public string Disable;
            public string Remark;
        }
 
        public class OuterClass
        {
            public bool phantom;
            public string id;
 
            public InternalClass data;
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            const string json = @"{""phantom"":true,
                                   ""id"":""ext-record-10"",
                                   ""data"":
                                  {""MID"":1019,
                                   ""Name"":""aaccccc"",
                                    ""Des"":""cc"",
                                    ""Disable"":""启用"",
                                    ""Remark"":""cccc""}}";
            JavaScriptSerializer ser = new JavaScriptSerializer();
            OuterClass foo = ser.Deserialize<OuterClass>(json); 
 
 
        }
 
 
JavaScriptSerializer类 需要引用System.Web.Extensions