using Newtonsoft.Json
首先添加Newtonsoft.Json的引用json
1.JSON序列化get
string JsonStr= JsonConvert.SerializeObject(Entity);string
public class RecordResult
{
[JsonProperty("status")]
public int Status { get; set; }
[JsonProperty("error")]
public int Error { get; set; }
}it
RecordResult result = new RecordResult();class
result.Status = 1;model
result.Error = "Error message";序列化
string jsonStr = JsonConvert.SerializeObject(result);引用
2.JSON反序列化error
Class model = JsonConvert.DeserializeObject<Class>(jsonstr);margin
var result = (RecordResult)JsonConvert.DeserializeObject(jsonstring, typeof(RecordResult))
//或者
var result = JsonConvert.DeserializeObject<RecordResult>(jsonstring)