mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-21 19:49:34 +08:00
更新 DataRequest, RunTime, GameMode; 添加 FunGameConfig (#33)
* 更新DataRequest GetResult<T> * 更新了DataRequest的构造方法,以及RunTime类 * 更新RunTime控制器 * 从Desktop复制Config到Core;更新常量 * 添加GameMode
This commit is contained in:
parent
42d0ca61c5
commit
b4ce65a35b
@ -13,7 +13,7 @@ namespace Milimoe.FunGame.Core.Api.Factory
|
||||
return RoomFactory.Create();
|
||||
}
|
||||
|
||||
public static Room Create(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.None, RoomState RoomState = RoomState.Created, string Password = "")
|
||||
public static Room Create(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, RoomState RoomState = RoomState.Created, string Password = "")
|
||||
{
|
||||
return new Room(Id, Roomid, CreateTime, RoomMaster, RoomType, RoomState, Password);
|
||||
}
|
||||
|
@ -3,13 +3,34 @@ using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Library.Exception;
|
||||
using Milimoe.FunGame.Core.Service;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Api.Transmittal
|
||||
{
|
||||
/// <summary>
|
||||
/// 需要配合Milimoe.FunGame.Core.Library.Constant.DataRequestType使用
|
||||
/// 确保已添加对应的枚举
|
||||
/// </summary>
|
||||
public class DataRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据请求结果
|
||||
/// </summary>
|
||||
public RequestResult Result => Worker.Result;
|
||||
|
||||
/// <summary>
|
||||
/// 详细错误信息
|
||||
/// </summary>
|
||||
public string Error => Worker.Error;
|
||||
|
||||
/// <summary>
|
||||
/// 获取ResultData中key值对应的Json字符串
|
||||
/// -- 此索引器仅返回Json字符串,对象类型请使用反序列化方法GetResult<T>() --
|
||||
/// -- 当然也可以自己反序列化 --
|
||||
/// -- 基本类型可能有效,但仍建议使用反序列化方法 --
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public object? this[string key]
|
||||
{
|
||||
get
|
||||
@ -22,31 +43,55 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 私有的实现类
|
||||
/// </summary>
|
||||
private readonly Request Worker;
|
||||
|
||||
public DataRequest(Socket Socket, DataRequestType RequestType)
|
||||
/// <summary>
|
||||
/// 基于本地已连接的Socket创建新的数据请求
|
||||
/// 使用RunTimeModel中的NewDataRequest创建一个新的请求
|
||||
/// </summary>
|
||||
/// <param name="Socket"></param>
|
||||
/// <param name="RequestType"></param>
|
||||
internal DataRequest(Socket Socket, DataRequestType RequestType)
|
||||
{
|
||||
Worker = new(Socket, RequestType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加数据
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void AddRequestData(string key, object? value)
|
||||
{
|
||||
if (Worker.RequestData.ContainsKey(key)) Worker.RequestData[key] = value;
|
||||
else Worker.RequestData.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向服务器发送数据请求
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public RequestResult SendRequest()
|
||||
{
|
||||
Worker.SendRequest();
|
||||
return Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定key对应的反序列化对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public T? GetResult<T>(string key)
|
||||
{
|
||||
object? obj = this[key];
|
||||
if (obj != null)
|
||||
{
|
||||
return (T)obj;
|
||||
return JsonManager.GetObject<T>(Worker.ResultData, key);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
||||
/// <param name="RoomState">房间状态</param>
|
||||
/// <param name="Password">房间密码</param>
|
||||
/// <returns></returns>
|
||||
public static Room GetRoom(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.None, RoomState RoomState = RoomState.Created, string Password = "")
|
||||
public static Room GetRoom(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, RoomState RoomState = RoomState.Created, string Password = "")
|
||||
{
|
||||
return RoomFactory.Create(Id, Roomid, CreateTime, RoomMaster, RoomType, RoomState, Password);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Controller
|
||||
{
|
||||
@ -6,8 +7,6 @@ namespace Milimoe.FunGame.Core.Controller
|
||||
{
|
||||
public abstract bool Connected { get; }
|
||||
|
||||
public abstract Task<bool> GetServerConnection();
|
||||
|
||||
public abstract Task<ConnectResult> Connect();
|
||||
|
||||
public abstract bool Disconnect();
|
||||
@ -19,5 +18,7 @@ namespace Milimoe.FunGame.Core.Controller
|
||||
public abstract Task AutoLogin(string Username, string Password, string AutoKey);
|
||||
|
||||
public abstract void WritelnSystemInfo(string msg);
|
||||
|
||||
public abstract DataRequest NewDataRequest(DataRequestType RequestType);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
|
||||
}
|
||||
|
||||
internal Room(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.None, RoomState RoomState = RoomState.Created, string Password = "")
|
||||
internal Room(long Id = 0, string Roomid = "-1", DateTime? CreateTime = null, User? RoomMaster = null, RoomType RoomType = RoomType.All, RoomState RoomState = RoomState.Created, string Password = "")
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Roomid = Roomid;
|
||||
|
@ -7,7 +7,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Event
|
||||
{
|
||||
public string RoomID { get; set; } = "";
|
||||
public long RoomMaster { get; set; } = 0;
|
||||
public RoomType RoomType { get; set; } = RoomType.None;
|
||||
public RoomType RoomType { get; set; } = RoomType.All;
|
||||
public RoomState RoomState { get; set; } = RoomState.Created;
|
||||
public bool HasPassword => Password.Trim() != "";
|
||||
public string Password { get; set; } = "";
|
||||
@ -20,7 +20,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Event
|
||||
GameMode.GameMode_Team => Constant.RoomType.Team,
|
||||
GameMode.GameMode_MixHasPass => Constant.RoomType.MixHasPass,
|
||||
GameMode.GameMode_TeamHasPass => Constant.RoomType.TeamHasPass,
|
||||
_ => Constant.RoomType.None
|
||||
_ => Constant.RoomType.All
|
||||
};
|
||||
this.Password = Password;
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||
|
||||
/// <summary>
|
||||
/// 从参数列表中获取指定索引的参数的Json字符串
|
||||
/// -- 此方法仅返回Json字符串,对象类型请使用反序列化方法GetParam<T>() --
|
||||
/// -- 此索引器仅返回Json字符串,对象类型请使用反序列化方法GetParam<T>() --
|
||||
/// -- 当然也可以自己反序列化 --
|
||||
/// -- 基本类型可能有效,但仍建议使用反序列化方法 --
|
||||
/// </summary>
|
||||
/// <param name="index">索引</param>
|
||||
/// <returns></returns>
|
||||
|
@ -71,9 +71,11 @@
|
||||
|
||||
public class GameMode
|
||||
{
|
||||
public const string GameMode_All = "所有模式";
|
||||
public const string GameMode_AllHasPass = "带密码的所有模式";
|
||||
public const string GameMode_Mix = "混战模式";
|
||||
public const string GameMode_Team = "团队模式";
|
||||
public const string GameMode_MixHasPass = "带密码的混战模式";
|
||||
public const string GameMode_Team = "团队模式";
|
||||
public const string GameMode_TeamHasPass = "带密码的团队模式";
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
public enum RoomType
|
||||
{
|
||||
None,
|
||||
All,
|
||||
Mix,
|
||||
Team,
|
||||
MixHasPass,
|
||||
@ -80,6 +80,12 @@
|
||||
public enum DataRequestType
|
||||
{
|
||||
UnKnown,
|
||||
GetNotice,
|
||||
GetRegVerifyCode,
|
||||
CreateRoom,
|
||||
UpdateRoom,
|
||||
GetRoomSettings,
|
||||
GetRoomPlayerCount,
|
||||
GetFindPasswordVerifyCode
|
||||
}
|
||||
|
||||
|
67
Model/FunGameConfig.cs
Normal file
67
Model/FunGameConfig.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
public class FunGameConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否自动连接服务器
|
||||
/// </summary>
|
||||
public bool FunGame_isAutoConnect { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否自动登录
|
||||
/// </summary>
|
||||
public bool FunGame_isAutoLogin { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否在匹配中
|
||||
/// </summary>
|
||||
public bool FunGame_isMatching { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接上服务器
|
||||
/// </summary>
|
||||
public bool FunGame_isConnected { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否正在重连
|
||||
/// </summary>
|
||||
public bool FunGame_isRetrying { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否自动重连
|
||||
/// </summary>
|
||||
public bool FunGame_isAutoRetry { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 当前游戏模式
|
||||
/// </summary>
|
||||
public string FunGame_GameMode { get; set; } = GameMode.GameMode_Mix;
|
||||
|
||||
/// <summary>
|
||||
/// 服务器名称
|
||||
/// </summary>
|
||||
public string FunGame_ServerName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 公告
|
||||
/// </summary>
|
||||
public string FunGame_Notice { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 自动登录的账号
|
||||
/// </summary>
|
||||
public string FunGame_AutoLoginUser { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 自动登录的密码
|
||||
/// </summary>
|
||||
public string FunGame_AutoLoginPassword { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 自动登录的秘钥
|
||||
/// </summary>
|
||||
public string FunGame_AutoLoginKey { get; set; } = "";
|
||||
}
|
||||
}
|
121
Model/RunTime.cs
121
Model/RunTime.cs
@ -1,4 +1,5 @@
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Controller;
|
||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
@ -6,16 +7,46 @@ using Milimoe.FunGame.Core.Library.Exception;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 此类实现服务器连接、断开连接、心跳检测、创建数据请求等功能
|
||||
/// -- 需要继承并实现部分方法 --
|
||||
/// </summary>
|
||||
public abstract class RunTime
|
||||
{
|
||||
public abstract Socket? Socket { get; }
|
||||
/// <summary>
|
||||
/// 与服务器的连接套接字实例
|
||||
/// </summary>
|
||||
public Socket? Socket => _Socket;
|
||||
|
||||
/// <summary>
|
||||
/// 套接字是否已经连接
|
||||
/// </summary>
|
||||
public bool Connected => _Socket != null && _Socket.Connected;
|
||||
|
||||
/// <summary>
|
||||
/// 接收服务器信息的线程
|
||||
/// </summary>
|
||||
protected Task? _ReceivingTask;
|
||||
|
||||
/// <summary>
|
||||
/// 用于类内赋值
|
||||
/// </summary>
|
||||
protected Socket? _Socket;
|
||||
|
||||
/// <summary>
|
||||
/// 是否正在接收服务器信息
|
||||
/// </summary>
|
||||
protected bool _IsReceiving;
|
||||
|
||||
/// <summary>
|
||||
/// 是否拥有一个控制器
|
||||
/// </summary>
|
||||
protected RunTimeController? _Controller;
|
||||
|
||||
/// <summary>
|
||||
/// 断开服务器连接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Disconnect()
|
||||
{
|
||||
bool result = false;
|
||||
@ -32,15 +63,43 @@ namespace Milimoe.FunGame.Core.Model
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Disconnected()
|
||||
/// <summary>
|
||||
/// 获取服务器地址
|
||||
/// </summary>
|
||||
/// <returns>string:IP地址;int:端口号</returns>
|
||||
/// <exception cref="FindServerFailedException"></exception>
|
||||
public (string, int) GetServerAddress()
|
||||
{
|
||||
Disconnect();
|
||||
try
|
||||
{
|
||||
string? ipaddress = (string?)Implement.GetFunGameImplValue(InterfaceType.IClient, InterfaceMethod.RemoteServerIP);
|
||||
if (ipaddress != null)
|
||||
{
|
||||
string[] s = ipaddress.Split(':');
|
||||
if (s != null && s.Length > 1)
|
||||
{
|
||||
return (s[0], Convert.ToInt32(s[1]));
|
||||
}
|
||||
}
|
||||
throw new FindServerFailedException();
|
||||
}
|
||||
catch (FindServerFailedException e)
|
||||
{
|
||||
_Controller?.WritelnSystemInfo(e.GetErrorInfo());
|
||||
return ("", 0);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void GetServerConnection();
|
||||
|
||||
/// <summary>
|
||||
/// 客户端需要自行实现连接服务器的事务
|
||||
/// </summary>
|
||||
/// <returns>支持异步</returns>
|
||||
public abstract Task<ConnectResult> Connect();
|
||||
|
||||
/// <summary>
|
||||
/// 关闭所有连接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Close()
|
||||
{
|
||||
try
|
||||
@ -65,8 +124,32 @@ namespace Milimoe.FunGame.Core.Model
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定处理异常的方法
|
||||
/// -- 一般放在catch中 --
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
public abstract void Error(Exception e);
|
||||
|
||||
/// <summary>
|
||||
/// 基于本地已连接的Socket创建新的数据请求
|
||||
/// </summary>
|
||||
/// <param name="RequestType"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ConnectFailedException"></exception>
|
||||
public DataRequest NewDataRequest(DataRequestType RequestType)
|
||||
{
|
||||
if (_Socket != null)
|
||||
{
|
||||
DataRequest request = new(_Socket, RequestType);
|
||||
return request;
|
||||
}
|
||||
throw new ConnectFailedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始接收服务器信息
|
||||
/// </summary>
|
||||
protected void StartReceiving()
|
||||
{
|
||||
_ReceivingTask = Task.Factory.StartNew(() =>
|
||||
@ -81,6 +164,10 @@ namespace Milimoe.FunGame.Core.Model
|
||||
_Socket?.StartReceiving(_ReceivingTask);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器已发送的信息为SocketObject数组
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected SocketObject[] GetServerMessage()
|
||||
{
|
||||
if (_Socket != null && _Socket.Connected)
|
||||
@ -90,6 +177,10 @@ namespace Milimoe.FunGame.Core.Model
|
||||
return Array.Empty<SocketObject>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 具体接收服务器信息以及处理信息的方法
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected SocketMessageType Receiving()
|
||||
{
|
||||
if (_Socket is null) return SocketMessageType.Unknown;
|
||||
@ -114,7 +205,10 @@ namespace Milimoe.FunGame.Core.Model
|
||||
break;
|
||||
|
||||
case SocketMessageType.HeartBeat:
|
||||
SocketHandler_HeartBeat(ServerMessage);
|
||||
if (_Socket != null && _Socket.Connected)
|
||||
{
|
||||
SocketHandler_HeartBeat(ServerMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case SocketMessageType.Unknown:
|
||||
@ -131,10 +225,23 @@ namespace Milimoe.FunGame.Core.Model
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接服务器的处理方法
|
||||
/// </summary>
|
||||
/// <param name="ServerMessage"></param>
|
||||
/// <returns></returns>
|
||||
protected abstract bool SocketHandler_Connect(SocketObject ServerMessage);
|
||||
|
||||
/// <summary>
|
||||
/// 与服务器断开连接的处理方法
|
||||
/// </summary>
|
||||
/// <param name="ServerMessage"></param>
|
||||
protected abstract void SocketHandler_Disconnect(SocketObject ServerMessage);
|
||||
|
||||
/// <summary>
|
||||
/// 心跳检测处理方法
|
||||
/// </summary>
|
||||
/// <param name="ServerMessage"></param>
|
||||
protected abstract void SocketHandler_HeartBeat(SocketObject ServerMessage);
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,39 @@ namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
public class Session
|
||||
{
|
||||
public Guid SocketToken { get; set; } = Guid.Empty; // SocketToken
|
||||
public Guid LoginKey { get; set; } = Guid.Empty; // LoginKey
|
||||
public User LoginUser { get; set; } = General.UnknownUserInstance; // 已登录的用户
|
||||
public string LoginUserName { get; set; } = ""; // 已登录用户名
|
||||
public Room InRoom { get; set; } = General.HallInstance; // 所处的房间
|
||||
/// <summary>
|
||||
/// 服务器IP地址
|
||||
/// </summary>
|
||||
public string Server_IP { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 服务器端口号
|
||||
/// </summary>
|
||||
public int Server_Port { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// SocketToken
|
||||
/// </summary>
|
||||
public Guid SocketToken { get; set; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// LoginKey
|
||||
/// </summary>
|
||||
public Guid LoginKey { get; set; } = Guid.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 已登录的用户
|
||||
/// </summary>
|
||||
public User LoginUser { get; set; } = General.UnknownUserInstance;
|
||||
|
||||
/// <summary>
|
||||
/// 已登录用户名
|
||||
/// </summary>
|
||||
public string LoginUserName { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 所处的房间
|
||||
/// </summary>
|
||||
public Room InRoom { get; set; } = General.HallInstance;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System.Text.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Milimoe.FunGame.Core.Library.Common.JsonConverter;
|
||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||
@ -58,19 +60,6 @@ namespace Milimoe.FunGame.Core.Service
|
||||
return JsonSerializer.Deserialize<object>(json, GeneralOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化多个Json对象
|
||||
/// 注意必须是相同的Json对象才可以使用此方法解析
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="json"></param>
|
||||
/// <returns></returns>
|
||||
internal static List<T> GetObjects<T>(string json)
|
||||
{
|
||||
json = "[" + json.Replace("}{", "},{") + "]"; // 将Json字符串转换为数组
|
||||
return JsonSerializer.Deserialize<List<T>>(json, GeneralOptions) ?? new List<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化SocketObject中索引为index的Json对象
|
||||
/// </summary>
|
||||
@ -86,5 +75,39 @@ namespace Milimoe.FunGame.Core.Service
|
||||
T? result = element.Deserialize<T>(GeneralOptions);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化Hashtable中Key对应的Json对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="table"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
internal static T? GetObject<T>(Hashtable table, string key)
|
||||
{
|
||||
if (table.ContainsKey(key))
|
||||
{
|
||||
JsonElement? element = (JsonElement?)table[key];
|
||||
if (element != null)
|
||||
{
|
||||
T? result = ((JsonElement)element).Deserialize<T>(GeneralOptions);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 反序列化多个Json对象
|
||||
/// 注意必须是相同的Json对象才可以使用此方法解析
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="json"></param>
|
||||
/// <returns></returns>
|
||||
internal static List<T> GetObjects<T>(string json)
|
||||
{
|
||||
json = "[" + json.Replace("}{", "},{") + "]"; // 将Json字符串转换为数组
|
||||
return JsonSerializer.Deserialize<List<T>>(json, GeneralOptions) ?? new List<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user