@@ -32,12 +32,23 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Ignore });
|
||||
}
|
||||
|
||||
// 通过类型参数反序列化 JSON 字符串为指定类型的对象
|
||||
/// <summary>
|
||||
/// 通过类型参数反序列化 JSON 字符串为指定类型的对象
|
||||
/// </summary>
|
||||
/// <param name="jsonStr"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static object JsonStrToObject(this string jsonStr, Type type)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(jsonStr, type);
|
||||
}
|
||||
|
||||
|
||||
public static Dictionary<string, object> ToDictionary(this object obj)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Include });
|
||||
return JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
|
||||
}
|
||||
/// <summary>
|
||||
/// 将对象序列化成稽查需要的Json字符串
|
||||
/// </summary>
|
||||
@@ -64,9 +75,7 @@ namespace IRaCIS.Core.Infrastructure.Extention
|
||||
foreach (PropertyInfo property in properties)
|
||||
{
|
||||
string propertyName = property.Name;
|
||||
Console.WriteLine(propertyName);
|
||||
object propertyValue = property.GetValue(obj);
|
||||
Console.WriteLine(propertyName);
|
||||
// 如果属性的类型是枚举,将其值保留为整数
|
||||
if (property.PropertyType.IsEnum || (Nullable.GetUnderlyingType(property.PropertyType)?.IsEnum == true && propertyValue!=null) )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user