private static void RecursiveObjectToString(JSONObject obj, StringBuilder sb, int level) { if (obj.IsDictionary) { sb.AppendLine(); RecursiveDictionaryToString(obj, sb, level + 1); } else if (obj.IsArray) { foreach (JSONObject o in obj.Array) { RecursiveObjectToString(o, sb, level); sb.AppendLine(); } } else // some sort of scalar value { sb.Append(obj.String); } }
private static void RecursiveDictionaryToString(JSONObject obj, StringBuilder sb, int level) { foreach (KeyValuePair<string, JSONObject> kvp in obj.Dictionary) { sb.Append(' ', level * 2); sb.Append(kvp.Key); sb.Append(" => "); RecursiveObjectToString(kvp.Value, sb, level); sb.AppendLine(); } }
/// <summary> /// Recursively constructs this JSONObject /// </summary> private static JSONObject Create(JsonValue o) { JSONObject obj = new JSONObject(); if (o is JsonObject) { } foreach (JsonObject a in o) { } if (o is JsonArray) { JsonArray objArray = (JsonArray)o; obj._arrayData = new JSONObject[objArray.Count]; for (int i = 0; i < obj._arrayData.Length; ++i) { obj._arrayData[i] = Create(objArray[i]); } } /* else if (o is Dictionary<string, object>) { obj._dictData = new Dictionary<string, JSONObject>(); var dict = (Dictionary<string, object>)o; foreach (string key in dict.Keys) { obj._dictData[key] = Create((JsonValue)dict[key]); } } */ else if (o != null) // o is a scalar { obj._stringData = o.ToString(); } return obj; }