using Newtonsoft.Json
首先添加Newtonsoft.Json的引用
1.JSON序列化
string JsonStr= JsonConvert.SerializeObject(Entity);
public class RecordResult
{
[JsonProperty("status")]
public int Status { get; set; }
[JsonProperty("error")]
public int Error { get; set; }
}
RecordResult result = new RecordResult();
result.Status = 1;
result.Error = "Error message";
string jsonStr = JsonConvert.SerializeObject(result);
2.JSON反序列化
Class model = JsonConvert.DeserializeObject<Class>(jsonstr);
var result = (RecordResult)JsonConvert.DeserializeObject(jsonstring, typeof(RecordResult))
//或者
var result = JsonConvert.DeserializeObject<RecordResult>(jsonstring)
本文介绍如何使用Newtonsoft.Json库进行JSON序列化和反序列化的操作。具体包括将C#对象转换为JSON字符串的方法及如何从JSON字符串中解析出C#对象的过程。

1356

被折叠的 条评论
为什么被折叠?



