Skip to content

Commit f0767c8

Browse files
committed
[删除]1. 删除Newtonsoft.Json 库的引用
1 parent 2639e95 commit f0767c8

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

GameFrameX.Foundation.Http.Normalization/GameFrameX.Foundation.Http.Normalization.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
3434
<OutputPath>..\bin\app</OutputPath>
3535
</PropertyGroup>
36-
<ItemGroup>
37-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
38-
</ItemGroup>
3936
<ItemGroup>
4037
<None Include="..\logo.png">
4138
<Pack>True</Pack>

GameFrameX.Foundation.Http.Normalization/HttpJsonResult.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
23

34
namespace GameFrameX.Foundation.Http.Normalization;
45

@@ -20,21 +21,21 @@ public sealed class HttpJsonResult
2021
/// 404: 资源未找到
2122
/// 500: 服务器内部错误
2223
/// </summary>
23-
[JsonProperty(PropertyName = "code")]
24+
[JsonPropertyName("code")]
2425
public int Code { get; set; }
2526

2627
/// <summary>
2728
/// 响应消息,提供关于请求结果的详细信息。
2829
/// 成功时通常为空字符串,失败时包含具体的错误信息。
2930
/// </summary>
30-
[JsonProperty(PropertyName = "message")]
31+
[JsonPropertyName("message")]
3132
public string Message { get; set; }
3233

3334
/// <summary>
3435
/// 响应数据,包含请求成功时返回的具体数据内容。
3536
/// 数据以JSON字符串的形式存储,可以包含任意类型的序列化数据。
3637
/// </summary>
37-
[JsonProperty(PropertyName = "data")]
38+
[JsonPropertyName("data")]
3839
public string Data { get; set; }
3940

4041
/// <summary>
@@ -44,7 +45,7 @@ public sealed class HttpJsonResult
4445
/// <returns>JSON格式的字符串表示。</returns>
4546
public override string ToString()
4647
{
47-
return JsonConvert.SerializeObject(this);
48+
return JsonSerializer.Serialize(this);
4849
}
4950

5051
/// <summary>
@@ -163,7 +164,7 @@ public static HttpJsonResult Success(object data)
163164
{
164165
Code = 0,
165166
Message = string.Empty,
166-
Data = JsonConvert.SerializeObject(data),
167+
Data = JsonSerializer.Serialize(data),
167168
};
168169
}
169170

GameFrameX.Foundation.Http.Normalization/HttpJsonResultHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json;
22

33
namespace GameFrameX.Foundation.Http.Normalization;
44

@@ -24,7 +24,7 @@ public static class HttpJsonResultHelper
2424
try
2525
{
2626
// 反序列化JSON字符串为HttpJsonResult对象
27-
var httpJsonResult = JsonConvert.DeserializeObject<HttpJsonResult>(jsonResult);
27+
var httpJsonResult = JsonSerializer.Deserialize<HttpJsonResult>(jsonResult);
2828
// 检查响应码是否表示成功
2929
if (httpJsonResult.Code != 0)
3030
{
@@ -34,7 +34,7 @@ public static class HttpJsonResultHelper
3434

3535
resultData.IsSuccess = true; // 设置成功标志
3636
// 反序列化数据部分,如果数据为空则返回类型T的默认实例
37-
resultData.Data = string.IsNullOrEmpty(httpJsonResult.Data) ? new T() : JsonConvert.DeserializeObject<T>(httpJsonResult.Data);
37+
resultData.Data = string.IsNullOrEmpty(httpJsonResult.Data) ? new T() : JsonSerializer.Deserialize<T>(httpJsonResult.Data);
3838
}
3939
catch (Exception e)
4040
{

0 commit comments

Comments
 (0)