diff --git a/Api/Utility/General.cs b/Api/Utility/General.cs index c3d2514..590cb18 100644 --- a/Api/Utility/General.cs +++ b/Api/Utility/General.cs @@ -125,10 +125,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// /// - public static string JsonSerialize(T obj) - { - return Service.JsonManager.GetString(obj); - } + public static string JsonSerialize(T obj) => Service.JsonManager.GetString(obj); /// /// 返回目标对象的Json字符串 可指定反序列化选项 @@ -137,10 +134,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// /// - public static string JsonSerialize(T obj, JsonSerializerOptions options) - { - return Service.JsonManager.GetString(obj, options); - } + public static string JsonSerialize(T obj, JsonSerializerOptions options) => Service.JsonManager.GetString(obj, options); /// /// 反序列化Json对象 @@ -148,10 +142,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// /// - public static T? JsonDeserialize(string json) - { - return Service.JsonManager.GetObject(json); - } + public static T? JsonDeserialize(string json) => Service.JsonManager.GetObject(json); /// /// 反序列化Json对象 可指定反序列化选项 @@ -160,10 +151,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// /// - public static T? JsonDeserialize(string json, JsonSerializerOptions options) - { - return Service.JsonManager.GetObject(json, options); - } + public static T? JsonDeserialize(string json, JsonSerializerOptions options) => Service.JsonManager.GetObject(json, options); /// /// 反序列化Hashtable中的Json对象 @@ -172,10 +160,26 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// /// - public static T? JsonDeserializeFromHashtable(Hashtable hashtable, string key) - { - return Service.JsonManager.GetObject(hashtable, key); - } + public static T? JsonDeserializeFromHashtable(Hashtable hashtable, string key) => Service.JsonManager.GetObject(hashtable, key); + + /// + /// 反序列化IEnumerable中的Json对象 + /// + /// + /// + /// + /// + public static T? JsonDeserializeFromIEnumerable(IEnumerable e, int index) => Service.JsonManager.GetObject(e, index); + + /// + /// 反序列化IEnumerable中的Json对象 可指定反序列化选项 + /// + /// + /// + /// + /// + /// + public static T? JsonDeserializeFromIEnumerable(IEnumerable e, int index, JsonSerializerOptions options) => Service.JsonManager.GetObject(e, index, options); /// /// 反序列化Hashtable中的Json对象 可指定反序列化选项 @@ -185,10 +189,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// /// - public static T? JsonDeserializeFromHashtable(Hashtable hashtable, string key, JsonSerializerOptions options) - { - return Service.JsonManager.GetObject(hashtable, key, options); - } + public static T? JsonDeserializeFromHashtable(Hashtable hashtable, string key, JsonSerializerOptions options) => Service.JsonManager.GetObject(hashtable, key, options); } #endregion diff --git a/Api/Utility/JsonTool.cs b/Api/Utility/JsonTool.cs index 13e5b76..d0059d7 100644 --- a/Api/Utility/JsonTool.cs +++ b/Api/Utility/JsonTool.cs @@ -75,6 +75,15 @@ namespace Milimoe.FunGame.Core.Api.Utility /// public T? GetObject(Hashtable table, string key) => JsonManager.GetObject(table, key, options); + /// + /// 反序列化IEnumerable中的Json对象 可指定反序列化选项 + /// + /// + /// + /// + /// + public T? JsonDeserializeFromIEnumerable(IEnumerable e, int index) => JsonManager.GetObject(e, index, options); + /// /// 反序列化多个Json对象 /// 注意必须是相同的Json对象才可以使用此方法解析 @@ -91,7 +100,7 @@ namespace Milimoe.FunGame.Core.Api.Utility { WriteIndented = true, ReferenceHandler = ReferenceHandler.IgnoreCycles, - Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter() } + Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter(), new UserConverter(), new RoomConverter() } }; } } diff --git a/Docs/api.xml b/Docs/api.xml index 7b3ec74..012d8f8 100644 --- a/Docs/api.xml +++ b/Docs/api.xml @@ -428,6 +428,25 @@ + + + 反序列化IEnumerable中的Json对象 + + + + + + + + + 反序列化IEnumerable中的Json对象 可指定反序列化选项 + + + + + + + 反序列化Hashtable中的Json对象 可指定反序列化选项 @@ -655,6 +674,15 @@ + + + 反序列化IEnumerable中的Json对象 可指定反序列化选项 + + + + + + 反序列化多个Json对象 @@ -1931,6 +1959,25 @@ + + + 反序列化IEnumerable中的Json对象 + + + + + + + + + 反序列化IEnumerable中的Json对象 + + + + + + + 反序列化Hashtable中Key对应的Json对象 diff --git a/Library/Common/JsonConverter/RoomConverter.cs b/Library/Common/JsonConverter/RoomConverter.cs index 58ff85c..e9c0d90 100644 --- a/Library/Common/JsonConverter/RoomConverter.cs +++ b/Library/Common/JsonConverter/RoomConverter.cs @@ -53,6 +53,14 @@ namespace Milimoe.FunGame.Core.Library.Common.JsonConverter case RoomQuery.Column_RoomType: room.RoomType = (RoomType)reader.GetInt64(); break; + + case RoomQuery.Column_GameMode: + room.GameMode = reader.GetString() ?? ""; + break; + + case RoomQuery.Column_GameMap: + room.GameMap = reader.GetString() ?? ""; + break; case RoomQuery.Column_RoomState: room.RoomState = (RoomState)reader.GetInt64(); diff --git a/Service/JsonManager.cs b/Service/JsonManager.cs index 0f499fa..e81fff6 100644 --- a/Service/JsonManager.cs +++ b/Service/JsonManager.cs @@ -122,6 +122,51 @@ namespace Milimoe.FunGame.Core.Service return default; } + /// + /// 反序列化IEnumerable中的Json对象 + /// + /// + /// + /// + /// + internal static T? GetObject(IEnumerable e, int index) + { + IEnumerable elements = e.Cast(); + if (elements.Count() > index) + { + JsonElement? element = (JsonElement?)elements.ElementAt(index); + if (element != null) + { + T? result = ((JsonElement)element).Deserialize(GeneralOptions); + return result; + } + } + return default; + } + + /// + /// 反序列化IEnumerable中的Json对象 + /// + /// + /// + /// + /// + /// + internal static T? GetObject(IEnumerable e, int index, JsonSerializerOptions options) + { + IEnumerable elements = e.Cast(); + if (elements.Count() > index) + { + JsonElement? element = (JsonElement?)elements.ElementAt(index); + if (element != null) + { + T? result = ((JsonElement)element).Deserialize(options); + return result; + } + } + return default; + } + /// /// 反序列化Hashtable中Key对应的Json对象 ///