- Timestamp:
- Aug 7, 2022, 3:02:24 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/7dtd-server-fixes/src/JSON/JSONObject.cs
r389 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONObject : JSONNode {6 private readonly Dictionary<string, J SONNode> nodes = new Dictionary<string, JSONNode> ();5 public class JsonObject : JsonNode { 6 private readonly Dictionary<string, JsonNode> nodes = new Dictionary<string, JsonNode> (); 7 7 8 public J SONNode this [string _name] {8 public JsonNode this [string _name] { 9 9 get => nodes [_name]; 10 10 set => nodes [_name] = value; … … 19 19 } 20 20 21 public bool TryGetValue (string _name, out J SONNode _node) {21 public bool TryGetValue (string _name, out JsonNode _node) { 22 22 return nodes.TryGetValue (_name, out _node); 23 23 } 24 24 25 public void Add (string _name, J SONNode _node) {25 public void Add (string _name, JsonNode _node) { 26 26 nodes.Add (_name, _node); 27 27 } … … 33 33 } 34 34 35 foreach ( KeyValuePair<string, JSONNode> kvpin nodes) {35 foreach ((string key, JsonNode value) in nodes) { 36 36 if (_prettyPrint) { 37 37 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); 38 38 } 39 39 40 _stringBuilder.Append ( string.Format ("\"{0}\":", kvp.Key));40 _stringBuilder.Append ($"\"{key}\":"); 41 41 if (_prettyPrint) { 42 42 _stringBuilder.Append (" "); 43 43 } 44 44 45 kvp.Value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1);45 value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1); 46 46 _stringBuilder.Append (","); 47 47 if (_prettyPrint) { … … 61 61 } 62 62 63 public static J SONObject Parse (string _json, ref int _offset) {63 public static JsonObject Parse (string _json, ref int _offset) { 64 64 //Log.Out ("ParseObject enter (" + offset + ")"); 65 J SONObject obj = new JSONObject ();65 JsonObject obj = new JsonObject (); 66 66 67 67 bool nextElemAllowed = true; … … 72 72 case '"': 73 73 if (nextElemAllowed) { 74 J SONString key = JSONString.Parse (_json, ref _offset);74 JsonString key = JsonString.Parse (_json, ref _offset); 75 75 Parser.SkipWhitespace (_json, ref _offset); 76 76 if (_json [_offset] != ':') { 77 throw new MalformedJ SONException (77 throw new MalformedJsonException ( 78 78 "Could not parse object, missing colon (\":\") after key"); 79 79 } 80 80 81 81 _offset++; 82 J SONNode val = Parser.ParseInternal (_json, ref _offset);82 JsonNode val = Parser.ParseInternal (_json, ref _offset); 83 83 obj.Add (key.GetString (), val); 84 84 nextElemAllowed = false; 85 85 } else { 86 throw new MalformedJ SONException (86 throw new MalformedJsonException ( 87 87 "Could not parse object, found new key without a separating comma"); 88 88 } … … 94 94 _offset++; 95 95 } else { 96 throw new MalformedJ SONException (96 throw new MalformedJsonException ( 97 97 "Could not parse object, found a comma without a key/value pair first"); 98 98 }
Note:
See TracChangeset
for help on using the changeset viewer.