1、首先下载 Newtonsoft.Json.dll 文件,然后添加Newtonsoft.Json的引用

2、using Newtonsoft.Json

3、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);
4、JSON反序列化
Class model = JsonConvert.DeserializeObject<Class>(jsonstr);
var result = (RecordResult)JsonConvert.DeserializeObject(jsonstring, typeof(RecordResult))
//或者
var result = JsonConvert.DeserializeObject<RecordResult>(jsonstring)
原文链接:https://www.cnblogs.com/kevin860/p/11113112.html
本文详细介绍了如何使用Newtonsoft.Json库进行JSON序列化和反序列化操作,包括下载并引用库文件、序列化C#对象为JSON字符串及从JSON字符串反序列化为C#对象的过程。
1353

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



