XFEExtension
【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
关注
0
Fork
0
Star
0
返回提交历史
Modified
XFEExtension.NetCore.Test/Program.cs
+1
-1
Modified
XFEExtension.NetCore/XFEExtension.NetCore.csproj
+5
-2
Modified
XFEExtension.NetCore/XFETransform/JsonConverter/IQueryableJsonNode.cs
+1
-1
Modified
XFEExtension.NetCore/XFETransform/JsonConverter/JsonComplexPropertyNode.cs
+1
-1
Modified
XFEExtension.NetCore/XFETransform/JsonConverter/JsonNodeConverter.cs
+13
-6
Modified
XFEExtension.NetCore/XFETransform/JsonConverter/QueryableJsonNode.cs
+1
-1
XFEstudio/XFEExtension
支持可空节点查询并优化JSON层级处理
将QueryableJsonNode索引器及AnalyzePropertyArray方法改为可空返回,查询不到节点时返回null。优化JSON解析层级逻辑,避免根节点被误移除。更新测试文件路径,提升版本至3.3.11。
95f43ab
代码差异
6 个文件
+22
-12
@@ -5,7 +5,7 @@ internal class Program
5
5
{
6
6
private static void Main(string[] args)
7
7
{
8
QueryableJsonNode jsonNode = @"C:\Users\XFEstudio\Desktop\测试\Json数组解析失败.txt".ReadOut()!;
8
QueryableJsonNode jsonNode = @"C:\Users\XFEstudio\Desktop\测试\Bilibili解析失败.txt".ReadOut()!;
9
9
//var testClass = new TestClass("123", "sda", 12);
10
10
//testClass.ToJson().CW();
11
11
}
@@ -5,7 +5,7 @@
5
5
<ImplicitUsings>enable</ImplicitUsings>
6
6
<Nullable>enable</Nullable>
7
7
<GenerateDocumentationFile>True</GenerateDocumentationFile>
8
<Version>3.3.10</Version>
8
<Version>3.3.11</Version>
9
9
<Title>XFEExtension</Title>
10
10
<RepositoryUrl>https://github.com/XFEstudio/XFEExtension</RepositoryUrl>
11
11
<AnalysisLevel>latest</AnalysisLevel>
@@ -20,8 +20,11 @@
20
20
<PackageTags>XFE;拓展;GPT;Server;服务器;测试;XFEExtension</PackageTags>
21
21
<PackageReleaseNotes>
22
22
## 调整
23
24
支持可空节点查询并优化JSON层级处理
23
25
24
修复部分Json解析问题
26
将QueryableJsonNode索引器及AnalyzePropertyArray方法改为可空返回,查询不到节点时返回null。
27
优化JSON解析层级逻辑,避免根节点被误移除。更新测试文件路径,提升版本至3.3.11。
25
28
26
29
## 新增
27
30
@@ -10,5 +10,5 @@ public interface IQueryableJsonNode
10
10
/// </summary>
11
11
/// <param name="nodeProperties">查询属性名称或指定操作</param>
12
12
/// <returns>下一个可查询节点</returns>
13
public QueryableJsonNode this[params string[] nodeProperties] { get; }
13
public QueryableJsonNode? this[params string[] nodeProperties] { get; }
14
14
}
@@ -6,7 +6,7 @@
6
6
public class JsonComplexPropertyNode : JsonNode, IQueryableJsonNode
7
7
{
8
8
///<inheritdoc/>
9
public QueryableJsonNode this[params string[] nodeProperties] => JsonNodeConverter.AnalyzePropertyArray(nodeProperties, this);
9
public QueryableJsonNode? this[params string[] nodeProperties] => JsonNodeConverter.AnalyzePropertyArray(nodeProperties, this);
10
10
/// <summary>
11
11
/// 是否是列表
12
12
/// </summary>
@@ -78,10 +78,12 @@ public class JsonNodeConverter(string jsonString)
78
78
else
79
79
Console.WriteLine($"设置复杂Json节点失败:{currentLayer}\t{currentPropertyName}\t{currentPropertyValue}");
80
80
}
81
if (currentPosition.Count > 0)
81
// Never remove the root position (index 0). Only pop when there are >1 entries.
82
if (currentPosition.Count > 1)
82
83
{
83
84
currentPosition.RemoveAt(currentPosition.Count - 1);
84
currentLayer--;
85
if (currentLayer > -1)
86
currentLayer--;
85
87
}
86
88
currentPropertyName = "";
87
89
currentPropertyValue = "";
@@ -131,8 +133,13 @@ public class JsonNodeConverter(string jsonString)
131
133
else
132
134
Console.WriteLine($"设置复杂Json节点失败:{currentLayer}\t{currentPropertyName}\t{currentPropertyValue}");
133
135
}
134
currentPosition.RemoveAt(currentPosition.Count - 1);
135
currentLayer--;
136
// Never remove the root position (index 0). Only pop when there are >1 entries.
137
if (currentPosition.Count > 1)
138
{
139
currentPosition.RemoveAt(currentPosition.Count - 1);
140
if (currentLayer > -1)
141
currentLayer--;
142
}
136
143
}
137
144
else
138
145
{
@@ -332,7 +339,7 @@ public class JsonNodeConverter(string jsonString)
332
339
};
333
340
return jsonPropertyNode;
334
341
}
335
internal static QueryableJsonNode AnalyzePropertyArray(string[] nodeProperties, JsonComplexPropertyNode jsonComplexPropertyNode)
342
internal static QueryableJsonNode? AnalyzePropertyArray(string[] nodeProperties, JsonComplexPropertyNode jsonComplexPropertyNode)
336
343
{
337
344
if (nodeProperties[0].StartsWith("package:", StringComparison.CurrentCultureIgnoreCase))
338
345
{
@@ -345,7 +352,7 @@ public class JsonNodeConverter(string jsonString)
345
352
}
346
353
else
347
354
{
348
return jsonComplexPropertyNode.DescendingNodes.Find(node => node.PropertyName == nodeProperties[0]) is JsonNode jsonNode ? new(jsonNode) : throw new InvalidOperationException();
355
return jsonComplexPropertyNode.DescendingNodes.Find(node => node.PropertyName == nodeProperties[0]) is JsonNode jsonNode ? new(jsonNode) : null;
349
356
}
350
357
}
351
358
}
@@ -7,7 +7,7 @@
7
7
public class QueryableJsonNode(JsonNode jsonNode) : INodeBase, IQueryableJsonNode
8
8
{
9
9
///<inheritdoc/>
10
public QueryableJsonNode this[params string[] nodeProperties] => OriginalNode is JsonComplexPropertyNode complexPropertyNode ? complexPropertyNode[nodeProperties] : throw new InvalidOperationException("该节点为简单节点,无法继续查找");
10
public QueryableJsonNode? this[params string[] nodeProperties] => OriginalNode is JsonComplexPropertyNode complexPropertyNode ? complexPropertyNode[nodeProperties] : throw new InvalidOperationException("该节点为简单节点,无法继续查找");
11
11
/// <summary>
12
12
/// 原始节点
13
13
/// </summary>