- Timestamp:
- Sep 10, 2014, 8:09:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/JSON/JSONArray.cs
r154 r187 9 9 private List<JSONNode> nodes = new List<JSONNode> (); 10 10 11 public JSONNode this [int index] { 12 get { return nodes [index]; } 13 set { nodes [index] = value; } 14 } 15 16 public int Count { 17 get { return nodes.Count; } 18 } 19 11 20 public void Add (JSONNode node) 12 21 { 13 nodes.Add (node);22 nodes.Add (node); 14 23 } 15 24 16 public override string ToString ( )25 public override string ToString (bool prettyPrint = false, int currentLevel = 0) 17 26 { 18 27 StringBuilder sb = new StringBuilder ("["); 28 if (prettyPrint) 29 sb.Append ('\n'); 19 30 foreach (JSONNode n in nodes) { 20 sb.Append (n.ToString ()); 31 if (prettyPrint) 32 sb.Append (new String ('\t', currentLevel + 1)); 33 sb.Append (n.ToString (prettyPrint, currentLevel + 1)); 21 34 sb.Append (","); 35 if (prettyPrint) 36 sb.Append ('\n'); 22 37 } 23 38 if (sb.Length > 1) 24 sb.Remove (sb.Length - 1, 1); 39 sb.Remove (sb.Length - (prettyPrint ? 2 : 1), 1); 40 if (prettyPrint) 41 sb.Append (new String ('\t', currentLevel)); 25 42 sb.Append ("]"); 26 43 return sb.ToString (); 44 } 45 46 public static JSONArray Parse (string json, ref int offset) 47 { 48 //Log.Out ("ParseArray enter (" + offset + ")"); 49 JSONArray arr = new JSONArray (); 50 51 bool nextElemAllowed = true; 52 offset++; 53 while (true) { 54 Parser.SkipWhitespace (json, ref offset); 55 56 switch (json [offset]) { 57 case ',': 58 if (!nextElemAllowed) { 59 nextElemAllowed = true; 60 offset++; 61 } else 62 throw new MalformedJSONException ("Could not parse array, found a comma without a value first"); 63 break; 64 case ']': 65 offset++; 66 //Log.Out ("JSON:Parsed Array: " + arr.ToString ()); 67 return arr; 68 default: 69 arr.Add (Parser.ParseInternal (json, ref offset)); 70 nextElemAllowed = false; 71 break; 72 } 73 } 27 74 } 28 75
Note:
See TracChangeset
for help on using the changeset viewer.