JSONObject.Absorb C# (CSharp) Method

Absorb() public method

public Absorb ( JSONObject, obj ) : void
obj JSONObject,
return void
	public void Absorb(JSONObject obj)
	{
		list.AddRange(obj.list);
		keys.AddRange(obj.keys);
		str = obj.str;
		n = obj.n;
		b = obj.b;
		type = obj.type;
	}
	public static JSONObject Create()

Usage Example

Example #1
0
 /// <summary>
 /// Merge object right into left recursively
 /// </summary>
 /// <param name="left">The left (base) object</param>
 /// <param name="right">The right (new) object</param>
 static void MergeRecur(JSONObject left, JSONObject right)
 {
     if (left.type == Type.NULL)
     {
         left.Absorb(right);
     }
     else if (left.type == Type.OBJECT && right.type == Type.OBJECT)
     {
         for (int i = 0; i < right.list.Count; i++)
         {
             string key = right.keys[i];
             if (right[i].isContainer)
             {
                 if (left.HasField(key))
                 {
                     MergeRecur(left[key], right[i]);
                 }
                 else
                 {
                     left.AddField(key, right[i]);
                 }
             }
             else
             {
                 if (left.HasField(key))
                 {
                     left.SetField(key, right[i]);
                 }
                 else
                 {
                     left.AddField(key, right[i]);
                 }
             }
         }
     }
     else if (left.type == Type.ARRAY && right.type == Type.ARRAY)
     {
         if (right.Count > left.Count)
         {
             Debug.LogError("Cannot merge arrays when right object has more elements");
             return;
         }
         for (int i = 0; i < right.list.Count; i++)
         {
             if (left[i].type == right[i].type)                                      //Only overwrite with the same type
             {
                 if (left[i].isContainer)
                 {
                     MergeRecur(left[i], right[i]);
                 }
                 else
                 {
                     left[i] = right[i];
                 }
             }
         }
     }
 }
All Usage Examples Of JSONObject::Absorb