mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-04-18 23: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>
|
||||
public static string Json(this object me, bool format = false)
|
||||
{
|
||||
return JsonSerializer.Serialize(
|
||||
me, new JsonSerializerOptions { WriteIndented = format, PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
||||
var defaultOptions = default(JsonSerializerOptions).NewJsonSerializerOptions();
|
||||
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