C#对没有规律的json字符串转化为对象序列化并遍历读取
比如如下json字符串,而且此字符串的键值是不定而且是有变化的
var jsonString={"BillDate":1,"TypeName":0,"StepNum":0,"CollectCode":0,"Uncollected":1,"Tax":0,"AbstractInfo":1}
现在我们要对这它进行转化并遍历读取:
/// <summary> /// 把json字符串转化为对象 /// </summary> /// <param name="Json"></param> /// <returns></returns> public static JObject ToJObject(this string Json) { return Json == null ? JObject.Parse("{}") : JObject.Parse(Json.Replace(" ", "")); }
var objData=jsonString.ToJObject(); foreach(var m in objData) { var aa = m.Key; var bb = m.Value; }
微信号:jamesworkshop 学习QQ群:364976091