JSON实例

实例一:

JSON实例

JSON实例
using System;
using System.Web.Script.Serialization;

namespace JSonDemo
{
    //实体类
    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public partial class Test : System.Web.UI.Page
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
            Button2.Enabled = false;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var person = new Person {Id = 1, Name = "王小王"};

            var jsonSerializer = new JavaScriptSerializer();
            //执行序列化
           var  personStr = jsonSerializer.Serialize(person);
            Label1.Text = personStr;
            Button2.Enabled = true;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           //执行反序列化
            var jsonSerializer = new JavaScriptSerializer();
            var _person = jsonSerializer.Deserialize<Person>(Label1.Text);
            Label2.Text = "这个是反序列化的结果:"+_person.Id +","+ _person.Name;

        }
    }

}
JSON实例

JSON实例

上一篇:PhpMyaAmin导入sql文件时出现You probably tried to upload too large file的解决办法


下一篇:如何用 ajax 连接mysql数据库,并且获取从中返回的数据。ajax获取从mysql返回的数据。responseXML分别输出不同数据的方法。