您的位置:首页 > Web前端 > JavaScript

关于JSON.NET中对json的序列化和反序列化

2011-07-20 14:06 459 查看
public class employee
{
private string firstName;
private string lastName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
}

public void Page_Load(object sender,EventArgs e)
{
string strJson = "{"firstName":"John","lastName":"Doe"}";
employee em = (employee)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJson, typeof(employee));
Response.Write("JSON格式的字符串生成对应的类实体:" + em.FirstName + "---" + em.LastName);
Response.Write("<br/><br/>类实体序列化成JSON格式的字符串:" + Newtonsoft.Json.JavaScriptConvert.SerializeObject(em));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: