- Timestamp:
- Jan 19, 2019, 6:12:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/JSON/JSONObject.cs
r326 r351 6 6 private readonly Dictionary<string, JSONNode> nodes = new Dictionary<string, JSONNode> (); 7 7 8 public JSONNode this [string name] {9 get { return nodes [ name]; }10 set { nodes [ name] = value; }8 public JSONNode this [string _name] { 9 get { return nodes [_name]; } 10 set { nodes [_name] = value; } 11 11 } 12 12 … … 19 19 } 20 20 21 public bool ContainsKey (string name) {22 return nodes.ContainsKey ( name);21 public bool ContainsKey (string _name) { 22 return nodes.ContainsKey (_name); 23 23 } 24 24 25 public void Add (string name, JSONNodenode) {26 nodes.Add ( name,node);25 public void Add (string _name, JSONNode _node) { 26 nodes.Add (_name, _node); 27 27 } 28 28 29 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {30 stringBuilder.Append ("{");31 if ( prettyPrint) {32 stringBuilder.Append ('\n');29 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 30 _stringBuilder.Append ("{"); 31 if (_prettyPrint) { 32 _stringBuilder.Append ('\n'); 33 33 } 34 34 35 35 foreach (KeyValuePair<string, JSONNode> kvp in nodes) { 36 if ( prettyPrint) {37 stringBuilder.Append (new string ('\t',currentLevel + 1));36 if (_prettyPrint) { 37 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); 38 38 } 39 39 40 stringBuilder.Append (string.Format ("\"{0}\":", kvp.Key));41 if ( prettyPrint) {42 stringBuilder.Append (" ");40 _stringBuilder.Append (string.Format ("\"{0}\":", kvp.Key)); 41 if (_prettyPrint) { 42 _stringBuilder.Append (" "); 43 43 } 44 44 45 kvp.Value.ToString ( stringBuilder, prettyPrint,currentLevel + 1);46 stringBuilder.Append (",");47 if ( prettyPrint) {48 stringBuilder.Append ('\n');45 kvp.Value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1); 46 _stringBuilder.Append (","); 47 if (_prettyPrint) { 48 _stringBuilder.Append ('\n'); 49 49 } 50 50 } 51 51 52 52 if (nodes.Count > 0) { 53 stringBuilder.Remove (stringBuilder.Length - (prettyPrint ? 2 : 1), 1);53 _stringBuilder.Remove (_stringBuilder.Length - (_prettyPrint ? 2 : 1), 1); 54 54 } 55 55 56 if ( prettyPrint) {57 stringBuilder.Append (new string ('\t',currentLevel));56 if (_prettyPrint) { 57 _stringBuilder.Append (new string ('\t', _currentLevel)); 58 58 } 59 59 60 stringBuilder.Append ("}");60 _stringBuilder.Append ("}"); 61 61 } 62 62 63 public static JSONObject Parse (string json, ref intoffset) {63 public static JSONObject Parse (string _json, ref int _offset) { 64 64 //Log.Out ("ParseObject enter (" + offset + ")"); 65 65 JSONObject obj = new JSONObject (); 66 66 67 67 bool nextElemAllowed = true; 68 offset++;68 _offset++; 69 69 while (true) { 70 Parser.SkipWhitespace ( json, refoffset);71 switch ( json [offset]) {70 Parser.SkipWhitespace (_json, ref _offset); 71 switch (_json [_offset]) { 72 72 case '"': 73 73 if (nextElemAllowed) { 74 JSONString key = JSONString.Parse ( json, refoffset);75 Parser.SkipWhitespace ( json, refoffset);76 if ( json [offset] != ':') {74 JSONString key = JSONString.Parse (_json, ref _offset); 75 Parser.SkipWhitespace (_json, ref _offset); 76 if (_json [_offset] != ':') { 77 77 throw new MalformedJSONException ( 78 78 "Could not parse object, missing colon (\":\") after key"); 79 79 } 80 80 81 offset++;82 JSONNode val = Parser.ParseInternal ( json, refoffset);81 _offset++; 82 JSONNode val = Parser.ParseInternal (_json, ref _offset); 83 83 obj.Add (key.GetString (), val); 84 84 nextElemAllowed = false; … … 92 92 if (!nextElemAllowed) { 93 93 nextElemAllowed = true; 94 offset++;94 _offset++; 95 95 } else { 96 96 throw new MalformedJSONException ( … … 100 100 break; 101 101 case '}': 102 offset++;102 _offset++; 103 103 104 104 //Log.Out ("JSON:Parsed Object: " + obj.ToString ());
Note:
See TracChangeset
for help on using the changeset viewer.