mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-04-20 01:22:51 +08:00
<fix> 将一个对象序列化成json文本
This commit is contained in:
parent
cc761e4939
commit
05ca80acda
@ -15,7 +15,19 @@ public static class ObjectExtensions
|
|||||||
/// <returns>json文本</returns>
|
/// <returns>json文本</returns>
|
||||||
public static string Json(this object me, bool format = false)
|
public static string Json(this object me, bool format = false)
|
||||||
{
|
{
|
||||||
return JsonSerializer.Serialize(
|
var defaultOptions = default(JsonSerializerOptions).NewJsonSerializerOptions();
|
||||||
me, new JsonSerializerOptions { WriteIndented = format, PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
defaultOptions.WriteIndented = format;
|
||||||
|
return Json(me, defaultOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将一个对象序列化成json文本
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="me">指定对象</param>
|
||||||
|
/// <param name="options">序列化选项</param>
|
||||||
|
/// <returns>json文本</returns>
|
||||||
|
public static string Json(this object me, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
return JsonSerializer.Serialize(me, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user