c#字符串json转换
///
/// 将Json字符串转换为实体对象
///
///
/// json字符串
/// 出现异常时是否抛到上级
///
public static T JsonToObject
{
T result = default(T);
try
{
result = JsonConvert.DeserializeObject
}
catch (Exception ex)
{
if (isThrowException)
{
throw ex;
}
}
return result;
}
///
/// 将对象序列化为json字符串
///
///
/// 出现异常时是否抛到上级
///
public static string ObjectToJson(object obj, bool isThrowException = false)
{
string result = string.Empty;
try
{
result = JsonConvert.SerializeObject(obj);
}
catch (Exception ex)
{
if (isThrowException)
{
throw ex;
}
}
return result;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
