c# 在.NET使用Newtonsoft.Json转换,读取,写入json
2021-03-31 17:29
标签:send new height 对象 重载 交换 文本 例子 cte 转自:http://blog.sina.com.cn/s/blog_70686f3a0101kemg.html c# 在.NET使用Newtonsoft.Json转换,读取,写入json 标签:send new height 对象 重载 交换 文本 例子 cte 原文地址:https://www.cnblogs.com/cyqdeshenluo/p/9253621.html
JsonConvert.DeserializeObject(string value, Type type),反序列化,它有个重载方法JsonConvert.DeserializeObject(string value, Type type, params JsonConverter[]
converters)
这两个方法可以实现基本的序列化和反序列化要求,请看下面的例子:
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Person person = new Person();
person.Name = "GoldenEasy";
person.Age = 25;
string strSerializeJSON = JsonConvert.SerializeObject(person);
Response.Write(strSerializeJSON);
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Person person = new Person();
person.Name = "GoldenEasy";
person.Age = 25;
string strSerializeJSON = JsonConvert.SerializeObject(person);
Person user = (Person)JsonConvert.DeserializeObject(strSerializeJSON, typeof(Person));
Response.Write(user.Name);
}
}
文章标题:c# 在.NET使用Newtonsoft.Json转换,读取,写入json
文章链接:http://soscw.com/index.php/essay/70561.html