mirror of
				https://github.com/nsnail/ns-ext.git
				synced 2025-11-04 15:10:50 +08:00 
			
		
		
		
	<fix> 将一个对象序列化成json文本
This commit is contained in:
		@@ -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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user