Ejemplo n.º 1
0
 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();
     }
 }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Recursively constructs this JSONObject 
        /// </summary>
        private static JSONObject Create(object o)
        {
            JSONObject obj = new JSONObject();
            if (o is object[])
            {
                object[] objArray = o as object[];
                obj._arrayData = new JSONObject[objArray.Length];
                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>();
                Dictionary<string, object> dict =
                    o as Dictionary<string, object>;
                foreach (string key in dict.Keys)
                {
                    obj._dictData[key] = Create(dict[key]);
                }
            }
            else if (o != null) // o is a scalar
            {
                obj._stringData = o.ToString();
            }

            return obj;
        }