C#中使用JsonConvert解析JSON

时间:2020-04-09 09:34:21   收藏:0   阅读:125

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)

  

 

原文:https://www.cnblogs.com/wfy680/p/12664401.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!