JSon转泛型

VS2008 
引用System.ServiceModel.Web.dll
引用System.Runtime.Serialization.dll



        private void Form1_Load(object sender, EventArgs e)
        {
            string _JsonText = System.IO.File.ReadAllText(@"C:\2.TXT");

            List<Test> _Test = new List<Test>();

            DataContractJsonSerializer _Json = new DataContractJsonSerializer(_Test.GetType());
            byte[] _Using = System.Text.Encoding.UTF8.GetBytes(_JsonText);
            System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream(_Using);
            _MemoryStream.Position = 0;

            _Test =(List<Test>)_Json.ReadObject(_MemoryStream);
            
        }

        public class Test
        {
            public int cId = 0;
            public string cName = "";
            public int amount = 0;
            public string price = "";
        }

posted on 2015-11-09 13:01  !无名之辈  阅读(257)  评论(0)    收藏  举报