AJAX编程经常需要Object<=>JSON之间转换,写了二个扩展方法:

public static string ToJSON(this object obj)

public static T ParseJSON<T>(this string str)

使用例子:

    protected void Page_Load(object sender, EventArgs e)
    {
        Person p = new Person
        {
            Name = "wuchang",
            Email = "wuchangx@qq.com",
            LastActive = DateTime.Now,
            Arr = new string[] { "arr1", "arr2" },
            Lst = new List<string>( new string[] { "lst1", "lst2" } )
        };
        string json = p.ToJSON();
        this.TextBox1.Text = json;
        Person pp = json.ParseJSON<Person>();
        this.TextBox2.Text = pp.ToJSON();
    }

相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2021-12-11
  • 2022-12-23
  • 2021-11-29
  • 2021-05-25
猜你喜欢
  • 2021-09-05
  • 2021-09-27
  • 2021-12-04
  • 2021-06-01
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
相关资源
相似解决方案