using System.Collections;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Unicode;
using Milimoe.FunGame.Core.Library.Common.JsonConverter;
using Milimoe.FunGame.Core.Library.Common.Network;
namespace Milimoe.FunGame.Core.Service
{
internal class JsonManager
{
///
/// 默认的序列化选项
///
internal static JsonSerializerOptions GeneralOptions { get; } = new()
{
WriteIndented = true,
PropertyNameCaseInsensitive = true,
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
ReferenceHandler = ReferenceHandler.IgnoreCycles,
Converters = { new DateTimeConverter(), new DataTableConverter(), new DataSetConverter(), new UserConverter(), new RoomConverter(),
new CharacterConverter(), new MagicResistanceConverter(), new EquipSlotConverter(), new SkillConverter(), new EffectConverter(), new ItemConverter(),
new InventoryConverter(), new NormalAttackConverter(), new ClubConverter(), new GoodsConverter(), new StoreConverter(),
new NovelOptionConverter(), new NovelNodeConverter()
}
};
///
/// 获取Json字符串
///
///
///
///
internal static string GetString(T obj)
{
return JsonSerializer.Serialize(obj, GeneralOptions);
}
///
/// 获取Json字符串
///
///
///
///
///
internal static string GetString(T obj, JsonSerializerOptions options)
{
return JsonSerializer.Serialize(obj, options);
}
///
/// 反序列化Json对象
///
///
///
///
internal static T? GetObject(string json)
{
return JsonSerializer.Deserialize(json, GeneralOptions);
}
///
/// 反序列化Json对象,使用
///
///
///
///
///
internal static T? GetObject(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
return JsonSerializer.Deserialize(ref reader, options);
}
///
/// 反序列化Json对象
///
///
///
///
///
internal static T? GetObject(string json, JsonSerializerOptions options)
{
return JsonSerializer.Deserialize(json, options);
}
///
/// 反序列化Json对象,此方法可能无法返回正确的类型,请注意辨别
///
///
///
internal static object? GetObject(string json)
{
return JsonSerializer.Deserialize