原文章
https://www.cnblogs.com/zhyue93/p/json_Deserialize.html
/// <summary>
/// 反序列化json字符串
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="jsonText"></param>
/// <returns></returns>
public static T FromJson<T>(string jsonText)
{
var json = new JsonSerializer
{
NullValueHandling = NullValueHandling.Ignore,
ObjectCreationHandling = ObjectCreationHandling.Replace,
MissingMemberHandling = MissingMemberHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
var sr = new StringReader(jsonText);
var reader = new JsonTextReader(sr);
var result = (T)json.Deserialize(reader, typeof(T));
reader.Close();
return result;
}
string jsonData = "{\"column\":\"1\"}";//,\"rows\":\"4\"
dynamic jsonObj = JsonHelper.FromJson<dynamic>(jsonData);
//List<dynamic>jsonObj = JsonHelper.FromJson<List<dynamic>>(jsonData);
string rows = jsonObj.rows;//不会报错 结果为null
Console.WriteLine(rows);
Console.ReadKey();