44// </copyright>
55// ------------------------------------------------------------------------------
66
7+ using System . Collections . ObjectModel ;
78using System . Diagnostics ;
9+ using System . Text . Json ;
10+ using System . Text . Json . Nodes ;
11+ using System . Text . Json . Serialization ;
812
913namespace Ycs
1014{
1115 public class ContentJson : IContentEx
1216 {
1317 internal const int _ref = 2 ;
1418
15- private readonly List < object > _content ;
19+ private readonly List < JsonNode > _content ;
1620
17- internal ContentJson ( IEnumerable < object > data )
21+ internal ContentJson ( IEnumerable < JsonNode > data )
1822 {
19- _content = new List < object > ( data ) ;
23+ _content = new List < JsonNode > ( data ) ;
2024 }
2125
22- private ContentJson ( List < object > other )
26+ private ContentJson ( List < JsonNode > other )
2327 {
2428 _content = other ;
2529 }
@@ -29,7 +33,7 @@ private ContentJson(List<object> other)
2933 public bool Countable => true ;
3034 public int Length => _content ? . Count ?? 0 ;
3135
32- public IReadOnlyList < object > GetContent ( ) => _content . AsReadOnly ( ) ;
36+ public IReadOnlyList < object > GetContent ( ) => new ReadOnlyCollection < object > ( _content . OfType < object > ( ) . ToList ( ) ) ;
3337
3438 public IContent Copy ( ) => new ContentJson ( _content ) ;
3539
@@ -68,22 +72,22 @@ void IContentEx.Write(IUpdateEncoder encoder, int offset)
6872 encoder . WriteLength ( len ) ;
6973 for ( int i = offset ; i < len ; i ++ )
7074 {
71- var jsonStr = Newtonsoft . Json . JsonConvert . SerializeObject ( _content [ i ] ) ;
75+ var jsonStr = JsonSerializer . Serialize ( _content [ i ] ) ;
7276 encoder . WriteString ( jsonStr ) ;
7377 }
7478 }
7579
7680 internal static ContentJson Read ( IUpdateDecoder decoder )
7781 {
7882 var len = decoder . ReadLength ( ) ;
79- var content = new List < object > ( len ) ;
83+ var content = new List < JsonNode > ( len ) ;
8084
8185 for ( int i = 0 ; i < len ; i ++ )
8286 {
8387 var jsonStr = decoder . ReadString ( ) ;
84- object jsonObj = string . Equals ( jsonStr , "undefined" )
88+ JsonNode jsonObj = string . Equals ( jsonStr , "undefined" )
8589 ? null
86- : Newtonsoft . Json . JsonConvert . DeserializeObject ( jsonStr ) ;
90+ : JsonSerializer . Deserialize < JsonNode > ( jsonStr ) ;
8791 content . Add ( jsonObj ) ;
8892 }
8993
0 commit comments