private void Stringify(int depth, StringBuilder builder, bool pretty = true) { if (depth++ <= 100) { switch (this.type) { case Type.BAKED: builder.Append(this.str); break; case Type.STRING: if (typeof(object).IsInstanceOfType(this.str)) { this.str = this.str.Replace("\n", "\\n"); } builder.AppendFormat("\"{0}\"", this.str); break; case Type.NUMBER: if (this.useInt) { builder.Append(this.i.ToString()); } else if (float.IsInfinity(this.n)) { builder.Append("\"INFINITY\""); } else if (float.IsNegativeInfinity(this.n)) { builder.Append("\"NEGINFINITY\""); } else if (float.IsNaN(this.n)) { builder.Append("\"NaN\""); } else { builder.Append(this.n.ToString()); } break; case Type.OBJECT: builder.Append("{"); if (this.list.Count > 0) { if (pretty) { builder.Append("\n"); } for (int l = 0; l < this.list.Count; l++) { string arg = this.keys[l]; JSONObject jSONObject = this.list[l]; if ((bool)jSONObject) { if (pretty) { for (int m = 0; m < depth; m++) { builder.Append("\t"); } } builder.AppendFormat("\"{0}\":", arg); jSONObject.Stringify(depth, builder, pretty); builder.Append(","); if (pretty) { builder.Append("\n"); } } } if (pretty) { builder.Length -= 2; } else { builder.Length--; } } if (pretty && this.list.Count > 0) { builder.Append("\n"); for (int n = 0; n < depth - 1; n++) { builder.Append("\t"); } } builder.Append("}"); break; case Type.ARRAY: builder.Append("["); if (this.list.Count > 0) { if (pretty) { builder.Append("\n"); } for (int i = 0; i < this.list.Count; i++) { if ((bool)this.list[i]) { if (pretty) { for (int j = 0; j < depth; j++) { builder.Append("\t"); } } this.list[i].Stringify(depth, builder, pretty); builder.Append(","); if (pretty) { builder.Append("\n"); } } } if (pretty) { builder.Length -= 2; } else { builder.Length--; } } if (pretty && this.list.Count > 0) { builder.Append("\n"); for (int k = 0; k < depth - 1; k++) { builder.Append("\t"); } } builder.Append("]"); break; case Type.BOOL: if (this.b) { builder.Append("true"); } else { builder.Append("false"); } break; case Type.NULL: builder.Append("null"); break; } } }