SetField() 공개 메소드

public SetField ( string name, JSONObject, obj ) : void
name string
obj JSONObject,
리턴 void
예제 #1
0
 private void SetVec2(Vector2 value)
 {
     JSONObject vecJson = new JSONObject();
     vecJson.SetField("x",value.x);
     vecJson.SetField("y",value.y);
     VariableManager.JsonRecord.SetField(ID,vecJson);
 }
예제 #2
0
 private void SetBoolList(List<bool> boolList)
 {
     JSONObject listJson = new JSONObject();
     for(int i=0;i<boolList.Count;i++)
     {
         listJson.SetField("item"+i,boolList[i]);
     }
     VariableManager.JsonRecord.SetField(ID,listJson);
 }
예제 #3
0
 public JSONObject GeneratePositionUpdatePacket()
 {
     if (!_positionUpdatePacket)
     {
         _positionUpdatePacket = new JSONObject();
         _positionUpdatePacket.SetField("pos", new JSONObject(JSONObject.Type.ARRAY));
     }
     _positionUpdatePacket.AddField("pos", delegate(JSONObject o)
     {
         o.Add(transform.position.x);
         o.Add(transform.position.y);
     });
     return _positionUpdatePacket;
 }
예제 #4
0
    public JSONObject createJsonObject(JSONObject json, string jsonStr)
    {
        jsonStr = jsonStr.Trim();
        int openingCurlyBraces                = 0;
        int firstCurlyBracesPosition          = 0;
        int endingCurlyBracesPosition         = 0;
        int endingCurlyBracesComputedPosition = 0;
        int openingBrackets                = 0;
        int firstBracketsPosition          = 0;
        int endingBracketsPosition         = 0;
        int endingBracketsComputedPosition = 0;
        int charPosition = 0;
        //json = new JSONObject ();

        string   propName    = "";
        bool     openQuote   = false;
        bool     inProp      = false;
        bool     inValue     = false;
        string   strValue    = "";
        int      intValue    = 0;
        float    floatValue  = 0f;
        bool     boolValue   = false;
        bool     inBrackets  = false;
        string   tempValue   = "";
        string   jsonElement = "";
        JsonType jsonMode    = JsonType.NotSet;

        foreach (char c in jsonStr)
        {
            if (json.type == JSONObject.Type.ARRAY)
            {
                inValue = true;
                inProp  = false;
            }
            if (c == '"' && !openQuote && !inProp && !inValue && openingCurlyBraces == 0 &&
                openingBrackets == 0)
            {
                openQuote = true;
                if (json.type != JSONObject.Type.ARRAY)
                {
                    inProp   = true;
                    propName = "";
                    inValue  = false;
                }
                else
                {
                    jsonMode = JsonType.String;
                }
            }
            else if (openQuote && inProp && !inValue && c != '"' &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                propName += c;
            }
            else if (c == '"' && openQuote && inProp && openingCurlyBraces == 0 &&
                     openingBrackets == 0)
            {
                openQuote = false;
                inProp    = false;
            }
            else if (c == ':' && !openQuote && !inProp && !inValue &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                inValue   = true;
                tempValue = "";
                jsonMode  = JsonType.NotSet;
            }
            else if ((c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' ||
                      c == '7' || c == '8' || c == '9' || c == '0' || c == '-') && !openQuote && !inProp &&
                     inValue && openingCurlyBraces == 0 && openingBrackets == 0)
            {
                tempValue += c;
                if (tempValue.Length == 1)
                {
                    jsonMode = JsonType.Int;
                }
            }
            else if (c == '.' && !openQuote && !inProp && inValue &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                tempValue += c;
                jsonMode   = JsonType.Float;
            }
            else if (c == '"' && !openQuote && !inProp && inValue &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                openQuote = true;
                jsonMode  = JsonType.String;
            }
            else if (openQuote && !inProp && inValue && c != '"' &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                strValue += c;
            }
            else if (c == '"' && openQuote && !inProp && inValue && jsonMode == JsonType.String &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                openQuote = false;
            }
            else if (c == ',' && !inProp && inValue && jsonMode == JsonType.String &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                if (json.type == JSONObject.Type.ARRAY)
                {
                    json.Add(strValue);
                    inValue = true;
                }
                else
                {
                    if (inBrackets)
                    {
                        inValue = true;
                        json.Add(strValue);
                    }
                    else
                    {
                        inValue = false;
                        json.SetField(propName, strValue);
                    }
                }
                strValue = "";
            }
            else if (c == ',' && !inProp && inValue && jsonMode == JsonType.Int &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                intValue  = Convert.ToInt32(tempValue.Trim());
                tempValue = "";

                if (json.type == JSONObject.Type.ARRAY)
                {
                    json.Add(intValue);
                }
                else
                {
                    if (inBrackets)
                    {
                        inValue = true;
                        json.Add(intValue);
                    }
                    else
                    {
                        inValue = false;
                        json.SetField(propName, intValue);
                    }
                }
            }
            else if (c == ',' && !inProp && inValue && jsonMode == JsonType.Float &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                floatValue = Convert.ToSingle(tempValue.Trim());
                tempValue  = "";
                //floatValue = float.Parse (tempValue.Trim (), System.Globalization.CultureInfo.InvariantCulture);
                if (json.type == JSONObject.Type.ARRAY)
                {
                    json.Add(floatValue);
                }
                else
                {
                    if (inBrackets)
                    {
                        inValue = true;
                        json.Add(floatValue);
                    }
                    else
                    {
                        inValue = false;
                        json.SetField(propName, floatValue);
                    }
                }
            }
            else if (c == ',' && !inProp && inValue && jsonMode == JsonType.NotSet &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                if (inBrackets)
                {
                    inValue = true;
                }
                else
                {
                    inValue = false;
                }

                if (tempValue.Trim().ToLower().Equals("null"))
                {
                    if (json.type == JSONObject.Type.ARRAY)
                    {
                        json.Add("null");
                    }
                    else
                    {
                        if (inBrackets)
                        {
                            json.Add("null");
                        }
                        else
                        {
                            json.SetField(propName, "null");
                        }
                    }
                }
                else if (tempValue.Trim().ToLower().Equals("false") ||
                         tempValue.Trim().ToLower().Equals("true"))
                {
                    boolValue = Convert.ToBoolean(tempValue.Trim());
                    if (json.type == JSONObject.Type.ARRAY)
                    {
                        json.Add(boolValue);
                    }
                    else
                    {
                        if (inBrackets)
                        {
                            json.Add(boolValue);
                        }
                        else
                        {
                            json.SetField(propName, boolValue);
                        }
                    }
                }
                tempValue = "";
            }
            else if (c == '{' && openingBrackets == 0)
            {
                if (openingCurlyBraces == 0)
                {
                    firstCurlyBracesPosition = charPosition + 1;
                }
                openingCurlyBraces++;
            }
            else if (c == '}' && openingBrackets == 0)
            {
                openingCurlyBraces--;
                if (openingCurlyBraces == 0)
                {
                    jsonElement = "";
                    endingCurlyBracesPosition         = charPosition;
                    endingCurlyBracesComputedPosition = endingCurlyBracesPosition - firstCurlyBracesPosition;
                    jsonElement = jsonStr.Substring(firstCurlyBracesPosition, endingCurlyBracesComputedPosition);
                    JSONObject jsonObject = new JSONObject();
                    jsonObject = createJsonObject(jsonObject, jsonElement);

                    if (json.type == JSONObject.Type.ARRAY)
                    {
                        json.Add(jsonObject);
                    }
                    else
                    {
                        if (propName != "")
                        {
                            json.SetField(propName, jsonObject);
                        }
                        else
                        {
                            json = jsonObject;
                        }
                    }
                    inValue = false;
                }
            }
            else if (c == '[' && openingCurlyBraces == 0)
            {
                if (openingBrackets == 0)
                {
                    firstBracketsPosition = charPosition;
                }
                openingBrackets++;
            }
            else if (c == ']' && openingCurlyBraces == 0)
            {
                openingBrackets--;
                if (openingBrackets == 0)
                {
                    endingBracketsPosition = charPosition + 1;
                    if ((firstBracketsPosition + 2) != endingBracketsPosition)
                    {
                        endingBracketsComputedPosition = endingBracketsPosition - firstBracketsPosition;
                        jsonElement = jsonStr.Substring(firstBracketsPosition, endingBracketsComputedPosition);
                        JSONObject jsonObjectArray = JSONObject.arr;
                        inBrackets      = true;
                        inValue         = true;
                        jsonElement     = jsonElement.TrimStart('[');
                        jsonElement     = jsonElement.TrimEnd(']');
                        jsonObjectArray = createJsonObject(jsonObjectArray, jsonElement);

                        if (json.type == JSONObject.Type.ARRAY)
                        {
                            json.Add(jsonObjectArray);
                        }
                        else
                        {
                            json.SetField(propName, jsonObjectArray);
                        }

                        inBrackets = false;
                        inValue    = false;
                    }
                    else
                    {
                        JSONObject jsonObjectArray = JSONObject.arr;
                        json.SetField(propName, jsonObjectArray);
                    }
                    inValue = false;
                }
            }
            else if (!openQuote && !inProp && inValue &&
                     openingCurlyBraces == 0 && openingBrackets == 0)
            {
                tempValue += c;
                jsonMode   = JsonType.NotSet;
            }
            charPosition++;
        }
        if (inValue)
        {
            if (jsonMode == JsonType.Int)
            {
                intValue = Convert.ToInt32(tempValue.Trim());
                if (json.type == JSONObject.Type.ARRAY)
                {
                    json.Add(intValue);
                }
                else
                {
                    json.SetField(propName, intValue);
                }
            }
            else if (jsonMode == JsonType.Float)
            {
                floatValue = Convert.ToSingle(tempValue.Trim());
                //floatValue = float.Parse (tempValue.Trim (), System.Globalization.CultureInfo.InvariantCulture);
                if (json.type == JSONObject.Type.ARRAY)
                {
                    json.Add(floatValue);
                }
                else
                {
                    json.SetField(propName, floatValue);
                }
            }
            else if (jsonMode == JsonType.String)
            {
                if (json.type == JSONObject.Type.ARRAY)
                {
                    json.Add(strValue);
                }
                else
                {
                    json.SetField(propName, strValue);
                }
                strValue = "";
            }
            else if (jsonMode == JsonType.NotSet)
            {
                inValue = false;
                if (tempValue.Trim().ToLower().Equals("null"))
                {
                    if (json.type == JSONObject.Type.ARRAY)
                    {
                        json.Add("null");
                    }
                    else
                    {
                        json.SetField(propName, "null");
                    }
                }
                else if (tempValue.Trim().ToLower().Equals("false") ||
                         tempValue.Trim().ToLower().Equals("true"))
                {
                    boolValue = Convert.ToBoolean(tempValue.Trim());
                    {
                        if (json.type == JSONObject.Type.ARRAY)
                        {
                            json.Add(boolValue);
                        }
                        else
                        {
                            json.SetField(propName, boolValue);
                        }
                    }
                }
            }
            inValue = false;
        }
        return(json);
    }
예제 #5
0
파일: JSONObject.cs 프로젝트: RHF01369/DS
    /// <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)
            {
#if UNITY_2 || UNITY_3 || UNITY_4 || UNITY_5
                UnityEngine.Debug.LogError
#else
                Debug.WriteLine
#endif
                    ("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];
                    }
                }
            }
        }
    }
예제 #6
0
 public ConfigCollector()
 {
     Json      = JSONObject.obj;
     m_jsonCfg = JSONObject.obj;
     Json.SetField("Config", m_jsonCfg);
 }
예제 #7
0
 public JSONObject jsonFromCS()
 {
     JSONObject j = new JSONObject("{\"method\":\"hogemethod\"}");
     Debug.Log( "j:" + j );
     j.SetField( "params", new JSONObject( "[1,2,\"hoge\"]") );
     Debug.Log( "j:" + j );
     return j;
 }
예제 #8
0
        JSONObject ToJson()
        {
            var json = new JSONObject();

            json.SetField("code", code);
            json.SetField("lv", lv);
            json.SetField("name", name);
            json.SetField("strong", strong);
            json.SetField("intelligence", intelligence);
            json.SetField("mystery", mystery);
            json.SetField("agile", agile);
            json.SetField("vital", vital);
            json.SetField("luck", luck);
            json.SetField("attribute", attribute.ToString());
            json.SetField("regist_tribe_1", regist_tribe_1.ToString());
            json.SetField("regist_tribe_2", regist_tribe_2.ToString());
            json.SetField("regist_tribe_3", regist_tribe_3.ToString());

            return(json);
        }
예제 #9
0
 public static void SetTotalCoins(float totalNum)
 {
     // set TotalCoins number
     saveData.SetField("totalCoins", totalNum);
 }
예제 #10
0
    JSONObject getPropObject(Type type, object value, RangeAttribute range = null, bool debug = false)
    {
        JSONObject po = new JSONObject();

        po.SetField("ACCESS", 3);

        JSONObject vo  = new JSONObject();
        JSONObject ro  = new JSONObject();
        JSONObject ro0 = new JSONObject();

        if (range != null)
        {
            ro0.SetField("MIN", range.min);
            ro0.SetField("MAX", range.max);
        }

        string typeString = type.ToString();
        string poType     = "";


        switch (typeString)
        {
        case "System.String":
        case "System.Char":
            vo.Add(value.ToString());
            poType = "s";
            break;

        case "System.Boolean":
            vo.Add((bool)value);
            poType = "T";
            break;

        case "System.Int32":
        case "System.Int64":
        case "System.Int16":
        case "System.UInt16":
        case "System.Byte":
        case "System.SByte":
        {
            //add range
            vo.Add((int)value);
            poType = "i";
        }
        break;

        case "System.Double":
        case "System.Single":
        {
            //add range
            vo.Add((float)value);
            poType = "f";
        }
        break;

        case "UnityEngine.Vector2":
        {
            Vector2 v = (Vector2)value;
            vo.Add(v.x);
            vo.Add(v.y);
            poType = "ff";
        }
        break;

        case "UnityEngine.Vector3":
        {
            Vector3 v = (Vector3)value;
            vo.Add(v.x);
            vo.Add(v.y);
            vo.Add(v.z);
            poType = "fff";
        }
        break;

        case "UnityEngine.Quaternion":
        {
            Vector3 v = ((Quaternion)value).eulerAngles;
            vo.Add(v.x);
            vo.Add(v.y);
            vo.Add(v.z);
            poType = "fff";
        }
        break;

        case "UnityEngine.Color":
        {
            Color c = (Color)value;
            vo.Add(ColorUtility.ToHtmlStringRGBA(c));
            poType = "r";
        }
        break;

        case "UnityEngine.Vector4":
        {
            Color c = (Color)(Vector4)value;
            vo.Add(ColorUtility.ToHtmlStringRGBA(c));
            poType = "r";
        }
        break;

        /*
         * case "UnityEngine.Material":
         * {
         *  Material m = (Material)value;
         *  if(m != null)
         *  {
         *      int numProps = m.shader.GetPropertyCount();
         *      for(int i=0;i<numProps;i++)
         *      {
         *          m.shader.GetPropertyAttributes(i);
         *      }
         *  }
         * }
         * break;
         */
        default:
            if (type.IsEnum)
            {
                JSONObject enumO = new JSONObject();

                FieldInfo[] fields = type.GetFields();

                foreach (var field in fields)
                {
                    if (field.Name.Equals("value__"))
                    {
                        continue;
                    }
                    enumO.Add(field.Name);
                }
                ro0.SetField("VALS", enumO);
                vo.Add(value.ToString());
                poType = "s";
            }
            else
            {
                // Debug.LogWarning("Field type not supported " + typeString);
                return(null);
            }
            break;
        }

        if (ro0 != null)
        {
            ro.Add(ro0);
        }
        po.SetField("VALUE", vo);
        po.SetField("TYPE", poType);
        po.SetField("RANGE", ro);

        return(po);
    }
예제 #11
0
    JSONObject getObjectData(GameObject go, string baseAddress = "")
    {
        JSONObject o = new JSONObject();

        o.SetField("ACCESS", 0);
        JSONObject co = new JSONObject();

        for (int i = 0; i < go.transform.childCount; i++)
        {
            GameObject cgo = go.transform.GetChild(i).gameObject;
            if (!checkFilteredObject(cgo))
            {
                continue;
            }
            string cgoName = SanitizeName(cgo.name);
            co.SetField(cgoName, getObjectData(cgo, baseAddress + "/" + cgoName));
        }

        Component[] comps = go.GetComponents <Component>();

        foreach (Component comp in comps)
        {
            int    dotIndex = comp.GetType().ToString().LastIndexOf(".");
            string compType = comp.GetType().ToString().Substring(Mathf.Max(dotIndex + 1, 0));

            //Debug.Log(go.name+" > Comp : " + compType);
            if (!checkFilteredComp(compType))
            {
                continue;
            }

            string compAddress = baseAddress + "/" + compType;

            JSONObject cco = new JSONObject();
            cco.SetField("ACCESS", 0);

            JSONObject ccco = new JSONObject();

            FieldInfo[] fields = comp.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);

            foreach (FieldInfo info in fields)
            {
                RangeAttribute rangeAttribute = info.GetCustomAttribute <RangeAttribute>();

                //Debug.Log(go.name+" > Info field type : " +info.FieldType.ToString() +" /" +compType);

                JSONObject io = getPropObject(info.FieldType, info.GetValue(comp), rangeAttribute, info.Name == "mainColor");

                if (io != null)
                {
                    string ioName   = SanitizeName(info.Name);
                    string fullPath = compAddress + "/" + ioName;
                    io.SetField("FULL_PATH", fullPath);
                    ccco.SetField(ioName, io);
                    compInfoMap.Add(fullPath, new CompInfo(comp, info));
                }
            }

            PropertyInfo[] props = comp.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty);
            foreach (PropertyInfo info in props)
            {
                if (!info.CanWrite)
                {
                    continue;
                }
                string propType = info.PropertyType.ToString();
                if (!acceptedParamTypes.Contains(propType))
                {
                    continue;                                            //
                }
                //if (propType == "UnityEngine.Component") continue; //fix deprecation error
                //if (propType == "UnityEngine.GameObject") continue; //fix deprecation error
                //if (propType == "UnityEngine.Matrix4x4") continue; //fix deprecation error
                //if (propType == "UnityEngine.Transform") continue; //fix deprecation error
                //if (propType == "UnityEngine.Mesh") continue; //fix deprecation error
                if (excludeInternalUnityParams)
                {
                    if (internalUnityParamsNames.Contains(info.Name))
                    {
                        continue;
                    }
                    if (compType == "Transform" && internalUnityTransformNames.Contains(info.Name))
                    {
                        continue;
                    }
                }


                RangeAttribute rangeAttribute = info.GetCustomAttribute <RangeAttribute>();
                JSONObject     io             = getPropObject(info.PropertyType, info.GetValue(comp), rangeAttribute, false);

                if (io != null)
                {
                    string ioName   = SanitizeName(info.Name);
                    string fullPath = compAddress + "/" + ioName;
                    io.SetField("FULL_PATH", fullPath);
                    ccco.SetField(SanitizeName(info.Name), io);
                    compInfoMap.Add(fullPath, new CompInfo(comp, info));
                }
            }

            if (compType == "VisualEffect")
            {
                VisualEffect vfx = comp as VisualEffect;
                List <VFXExposedProperty> vfxProps = new List <VFXExposedProperty>();
                vfx.visualEffectAsset.GetExposedProperties(vfxProps);
                foreach (var p in vfxProps)
                {
                    //Debug.Log("Here " + p.name+" / "+p.type.ToString());
                    JSONObject io = getPropObject(p.type, getVFXPropValue(vfx, p.type, p.name));

                    if (io != null)
                    {
                        string sName    = SanitizeName(p.name);
                        string fullPath = compAddress + "/" + sName;
                        io.SetField("FULL_PATH", fullPath);
                        ccco.SetField(SanitizeName(sName), io);
                        compInfoMap.Add(fullPath, new CompInfo(comp as VisualEffect, p.name, p.type));
                    }
                }
            }
            else if (compType == "Volume")
            {
                //Volume v = comp as Volume;
            }
            else if (compType != "Transform")     //Avoid methods of internal components
            {
                MethodInfo[] methods = comp.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                foreach (MethodInfo info in methods)
                {
                    if (info.IsSpecialName && (info.Name.StartsWith("set_") || info.Name.StartsWith("get_")))
                    {
                        continue;                                                                                           //do not care for accessors
                    }
                    ParameterInfo[] paramInfos        = info.GetParameters();
                    bool            requiresArguments = false;
                    foreach (ParameterInfo paramInfo in paramInfos)
                    {
                        if (!paramInfo.HasDefaultValue)
                        {
                            requiresArguments = true;
                            break;
                        }
                    }

                    if (!requiresArguments)
                    {
                        JSONObject mo = new JSONObject();
                        mo.SetField("ACCESS", 3);
                        String ioName   = SanitizeName(info.Name);
                        string fullPath = compAddress + "/" + ioName;
                        mo.SetField("TYPE", "N");
                        mo.SetField("FULL_PATH", fullPath);
                        ccco.SetField(ioName, mo);
                        compInfoMap.Add(fullPath, new CompInfo(comp, info));

                        //Debug.Log("Added method : " + ioName);
                    }
                    else
                    {
                        //  Debug.Log("Method : " + info.Name + " requires arguments, not exposing");
                    }
                }
            }

            cco.SetField("CONTENTS", ccco);
            co.SetField(SanitizeName(compType), cco);
        }

        o.SetField("CONTENTS", co);

        return(o);
    }
예제 #12
0
        JSONObject ToJson()
        {
            var json = new JSONObject();

            json.SetField("id", Id);
            json.SetField("description", Description);
            json.SetField("sell_price", SellPrice);
            json.SetField("code", Code);
            json.SetField("lv", Lv);
            json.SetField("name", Name);
            json.SetField("not_found_name", NotFoundName);
            json.SetField("power", Power);
            json.SetField("deffense", Deffense);
            json.SetField("avoidance", Avoidance);
            json.SetField("hit", Hit);
            json.SetField("attribute", Attribute.ToString());
            json.SetField("regist_tribe", RegistTribe.ToString());

            return(json);
        }
 static void PutHighScore(JSONObject playerObject, int playerScore)
 {
     playerObject.SetField(FIELD_SCORE, playerScore);
 }
예제 #14
0
	static void MergeRecur(JSONObject left, JSONObject right) {
		if(right.type == JSONObject.Type.OBJECT) {
			for(int i = 0; i < right.list.Count; i++) {
				if(right.keys[i] != null) {
					string key = (string)right.keys[i];
					JSONObject val = (JSONObject)right.list[i];
					if(val.type == JSONObject.Type.ARRAY || val.type == JSONObject.Type.OBJECT) {
						if(left.HasField(key))
							MergeRecur(left[key], val);
						else
							left.AddField(key, val);
					} else {
						if(left.HasField(key))
							left.SetField(key, val);
						else
							left.AddField(key, val);
					}
				}
			}
		}// else left.list.Add(right.list);
	}
예제 #15
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)
         {
             if (GLog.IsLogErrorEnabled)
             {
                 GLog.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];
                 }
             }
         }
     }
 }
예제 #16
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 == JSONObject.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 = (string)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];
					}
				}
			}
		}
	}
예제 #17
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) {
				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];
					}
				}
			}
		}
	}