当前位置: 首页>>代码示例>>C#>>正文


C# JSONObject.HasField方法代码示例

本文整理汇总了C#中JSONObject.HasField方法的典型用法代码示例。如果您正苦于以下问题:C# JSONObject.HasField方法的具体用法?C# JSONObject.HasField怎么用?C# JSONObject.HasField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONObject的用法示例。


在下文中一共展示了JSONObject.HasField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Deserialize

        public static void Deserialize(this Template template)
        {
            template.Clear();

            var tplJs = new JSONObject(template.JSON);

            // Discard templates without the Operators and Connections fields
            if (tplJs.HasField("Operators") && tplJs.HasField("Connections")) {
                var opsJs = tplJs.GetField("Operators");
                var connsJs = tplJs.GetField("Connections");
                foreach (var opJs in opsJs.list) {
                    var type = System.Type.GetType(opJs["Type"].str);
                    var op = (Operator) System.Activator.CreateInstance(type);
                    op.Deserialize(opJs);
                    template.AddOperator(op, false);
                }
                foreach (var connJs in connsJs.list) {

                    // Discard connections with invalid Operator GUIDs
                    if (!template.Operators.ContainsKey(connJs["From"].str) || !template.Operators.ContainsKey(connJs["To"].str)) {
                        Debug.LogWarning("Discarding connection in template due to an invalid Operator GUID");
                        continue;
                    }

                    Operator fromOp = template.Operators[connJs["From"].str];
                    IOOutlet output = fromOp.GetOutput(connJs["Output"].str);

                    Operator toOp = template.Operators[connJs["To"].str];
                    IOOutlet input = toOp.GetInput(connJs["Input"].str);

                    template.Connect(fromOp, output, toOp, input, false);
                }
            }
        }
开发者ID:BrettRToomey,项目名称:forge,代码行数:34,代码来源:TemplateSerializer.cs

示例2: UnSerialize

    public static JSONAble UnSerialize(JSONObject jsonObject)
    {
        JSONAble r = null;

        if (jsonObject.HasField("_class") && jsonObject.HasField("_data"))
        {
            string c = jsonObject.GetField("_class").str;
            Type t = Type.GetType(c);
            if (t.IsSubclassOf(typeof(JSONAble)))
            {
                if (t.IsSubclassOf(typeof(ScriptableObject)))
                {
                    r = ScriptableObject.CreateInstance(t) as JSONAble;
                    r.fromJSONObject(jsonObject.GetField("_data"));
                }
            }
        }
        else if (jsonObject.IsArray)
        {
            r = ScriptableObject.CreateInstance<IsoUnityCollectionType>();
            r.fromJSONObject(jsonObject);
        }
        else if (jsonObject.IsString || jsonObject.IsNumber || jsonObject.IsBool)
        {
            r = ScriptableObject.CreateInstance<IsoUnityBasicType>();
            r.fromJSONObject(jsonObject);
        }

        return r;
    }
开发者ID:NasK1991,项目名称:IsoMonks,代码行数:30,代码来源:JSONSerializer.cs

示例3: ParseUnitObject

	public static bool ParseUnitObject( JSONObject _UnitNode , 
										ref string _UnitName ,
										ref string _PrefabName ,
										ref Vector3 _InitPosition ,
										ref Quaternion _InitQuaternion )
	{
		if( true == _UnitNode.HasField( "name" ) && 
			true == _UnitNode.HasField( "prefabName" ) 
			)
		{
			
			_UnitName = _UnitNode.GetField( "name" ).str ;
			
			Debug.Log( "JSonParseUtility01:ParseUnitObject() _UnitName=" + _UnitName) ;
			
			_PrefabName = _UnitNode.GetField( "prefabName" ).str ;
			
			if( true == _UnitNode.HasField( "position3D" )  )
			{
				JSONObject positione3DNode = _UnitNode.GetField( "position3D" ) ;
				ParsePosition( positione3DNode , 
							   ref _InitPosition ) ;
			}
			
			if( true == _UnitNode.HasField( "orientationEuler" ) )
			{
				JSONObject orientationNode = _UnitNode.GetField( "orientationEuler" ) ;
				ParseQuaternion( orientationNode , 
								 ref _InitQuaternion ) ;					
			}	
			return true ;
		}
		return false ;
	}	
开发者ID:NDark,项目名称:Ntust2013Unity_GitHub,代码行数:34,代码来源:JSonParseUtility01.cs

示例4: CreateFromJson

    public static GameModeDescription CreateFromJson(JSONObject jsonObject)
    {
        if (jsonObject == null)
        {
            Debug.LogWarning("There is no gameMode");
            return new GameModeDescription()
            {
                Mode = "TargetScore",
                TargetScore = 3000,
                Turns = 40
            };
            /*return new GameModeDescription()
            {
                Mode = "TargetChuzzle",
                Turns = 30,
                Amount = 20
            };*/
            /*return new GameModeDescription()
            {
                Mode = "TargetPlace",
                Turns = 30
            };*/
        }

        var desc = new GameModeDescription
        {
            Mode = jsonObject.GetField("Mode").str,
            Turns = (int) jsonObject.GetField("Turns").n,
            TargetScore = jsonObject.HasField("TargetScore") ? (int) jsonObject.GetField("TargetScore").n : 0,
            Amount = jsonObject.HasField("Amount") ? (int) jsonObject.GetField("Amount").n : 0
        };
        return desc;
    }
开发者ID:GreatVV,项目名称:loadzzer,代码行数:33,代码来源:GameModeFactory.cs

示例5: FromJson

    public static SerializedLevel FromJson(JSONObject jsonObject)
    {
        Debug.Log("Print: \n" + jsonObject);
        var serializedLevel = new SerializedLevel();
        serializedLevel.Name = jsonObject.GetField("name").str;

        serializedLevel.Width = (int) jsonObject.GetField("width").n;
        serializedLevel.Height = (int) jsonObject.GetField("height").n;
        serializedLevel.NumberOfColors = jsonObject.HasField("numberOfColors")
            ? (int) jsonObject.GetField("numberOfColors").n
            : 6;
        serializedLevel.Seed = jsonObject.HasField("seed") ? (int) jsonObject.GetField("seed").n : 1;

        serializedLevel.GameMode = GameModeDescription.CreateFromJson(jsonObject.GetField("gameMode"));

        var array = jsonObject.GetField("map").list;
        foreach (var tile in array)
        {
            var x = array.IndexOf(tile)%serializedLevel.Width;
            var y = serializedLevel.Height - (array.IndexOf(tile)/serializedLevel.Width) - 1;

            var tileType = (int) tile.n;
            switch (tileType)
            {
                case (0): //empty
                    break;
                case (2): // place
                    serializedLevel.SpecialCells.Add(new Cell(x, y) {HasPlace = true});
                    break;
                case (3): //counter
                    serializedLevel.SpecialCells.Add(new Cell(x, y) {HasCounter = true});
                    break;
                default: // block
                    serializedLevel.SpecialCells.Add(new Cell(x, y, CellTypes.Block));
                    break;
            }
        }

        serializedLevel.Stages = CreateStagesFromJsonObject(jsonObject.GetField("stages"));

        serializedLevel.Star1Score = jsonObject.HasField("Star1Score")
            ? (int) jsonObject.GetField("Star1Score").n
            : 1000;
        serializedLevel.Star2Score = jsonObject.HasField("Star2Score")
            ? (int) jsonObject.GetField("Star2Score").n
            : 2000;
        serializedLevel.Star3Score = jsonObject.HasField("Star3Score")
            ? (int) jsonObject.GetField("Star3Score").n
            : 3000;

        return serializedLevel;
    }
开发者ID:GreatVV,项目名称:loadzzer,代码行数:52,代码来源:SerializedLevel.cs

示例6: GetErrorMessage

 public string GetErrorMessage(JSONObject json)
 {
     if (json.HasField(((int) ParameterCode.Error).ToString()))
     {
         return json.GetField(((int) ParameterCode.Error).ToString()).str;
     }
     return null;
 }
开发者ID:alvyxaz,项目名称:dagger-online,代码行数:8,代码来源:BaseGameHandler.cs

示例7: ParsePosition

	// 分析位置 包含座標及位置物件
	public static bool ParsePosition( JSONObject _PositionNode , 
									  ref Vector3 _Pos )
	{
		if( true == _PositionNode.HasField( "x" ) &&
			true == _PositionNode.HasField( "y" ) &&
			true == _PositionNode.HasField( "z" ) )
		{
			string strx = _PositionNode.GetField("x").str ;
			string stry = _PositionNode.GetField("y").str ;
			string strz = _PositionNode.GetField("z").str ;
			float x , y , z ;
			float.TryParse( strx , out x ) ;
			float.TryParse( stry , out y ) ;
			float.TryParse( strz , out z ) ;
			_Pos = new Vector3( x , y , z ) ;			
			return true ;
		}
		return false ;
	}
开发者ID:NDark,项目名称:Ntust2013Unity_GitHub,代码行数:20,代码来源:JSonParseUtility01.cs

示例8: getConfigValue

        public static string getConfigValue(string key)
        {
            JSONObject config = new JSONObject(GameConfigData);

            if(config.HasField("key")){
                return config.GetField(key).Print(false);
            }

            return null;
        }
开发者ID:spilgames,项目名称:spil_event_unity_plugin,代码行数:10,代码来源:ConfigResponse.cs

示例9: ParseQuaternion

	// 分析旋轉
	public static bool ParseQuaternion( JSONObject _OrientationNode , 
						  				ref Quaternion _Orientation )
	{
		if( true == _OrientationNode.HasField( "x" ) &&
			true == _OrientationNode.HasField( "y" ) &&
			true == _OrientationNode.HasField( "z" ) )
		{		
			string strx = _OrientationNode.GetField("x").str ;
			string stry = _OrientationNode.GetField("y").str ;
			string strz = _OrientationNode.GetField("z").str ;
			float x , y , z ;
			float.TryParse( strx , out x ) ;
			float.TryParse( stry , out y ) ;
			float.TryParse( strz , out z ) ;									
			_Orientation = Quaternion.Euler( -x , -y , -z ) ;
			// Debug.Log( "XMLParseUtilityPartial02:ParseQuaternion() x=" + x + "," + y + ",z" + z ) ;
			return true ;
		}
		return false ;
	}		
开发者ID:NDark,项目名称:Ntust2013Unity_GitHub,代码行数:21,代码来源:JSonParseUtility01.cs

示例10: CheckSlotGameConifg

    public static void CheckSlotGameConifg()
    {
        JSONObject slotConfigJSON = new JSONObject(GetData("requestConfig"));
        JSONObject localConfigJSON = new JSONObject(System.IO.File.ReadAllText (Application.streamingAssetsPath + "/defaultGameConfig.json"));
        if(slotConfigJSON.HasField("androidSdkConfig") && localConfigJSON.HasField("androidSdkConfig")){
            string slotConfig = slotConfigJSON.GetField("androidSdkConfig").Print(false);
            string localConfig = localConfigJSON.GetField("androidSdkConfig").Print(false);

            if(!localConfig.Equals(slotConfig)){
                UnityEngine.Debug.Log("The local \"defaultGameConfig.json\" file is out-of-sync with the SLOT configuration. Please make sure to update your file with the latest changes from SLOT before building!");
            }
        }
    }
开发者ID:spilgames,项目名称:spil_event_unity_plugin,代码行数:13,代码来源:SpilAndroidBuildPostProcess.cs

示例11: MarketItem

        /**
         * Constructor.
         * Generates an instance of <code>MarketItem</code> from a <code>JSONObject</code>.
         *
         * @param jsonObject a <code>JSONObject</code> representation of the wanted
         *                   <code>MarketItem</code>.
         * @throws JSONException
         */
        public MarketItem(JSONObject jsonObject)
        {
            //MarketItem miDeserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<MarketItem>(jsonObject.ToString());
            if (jsonObject.HasField(StoreJSONConsts.MARKETITEM_MANAGED))
            {
                int isManaged = (int)jsonObject[StoreJSONConsts.MARKETITEM_MANAGED].n;
                SoomlaUtils.LogDebug(TAG, isManaged.ToString());
                if (isManaged == 0)
                {
                    this.mManaged = Managed.MANAGED;
                }
                else
                {
                    this.mManaged = Managed.UNMANAGED;
                }

            }
            else
            {
                this.mManaged = Managed.UNMANAGED;
            }
            if (jsonObject.HasField(StoreJSONConsts.MARKETITEM_PRODUCT_ID))
            {
                this.mProductId = jsonObject[StoreJSONConsts.MARKETITEM_PRODUCT_ID].str;
            }
            else
            {
                SoomlaUtils.LogError(TAG, "Market Item No Product ID");
            }
            this.mPrice = (double)jsonObject[StoreJSONConsts.MARKETITEM_PRICE].n;

            this.mMarketPriceAndCurrency = jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICE].str;
            this.mMarketTitle = jsonObject[StoreJSONConsts.MARKETITEM_MARKETTITLE].str;
            this.mMarketDescription = jsonObject[StoreJSONConsts.MARKETITEM_MARKETDESC].str;
            this.mMarketCurrencyCode = jsonObject[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE].str;
            this.mMarketPriceMicros = (long)jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS].n;

        }
开发者ID:Ratel13,项目名称:wp-store,代码行数:46,代码来源:MarketItem.cs

示例12: MarketItem

        /// <summary>
        /// Constructor.
        /// Generates an instance of <c>MarketItem</c> from a <c>JSONObject<c>.
        /// </summary>
        /// <param name="jsonObject">A <c>JSONObject</c> representation of the wanted 
        /// <c>MarketItem</c>.</param>
        public MarketItem(JSONObject jsonObject)
        {
            string keyToLook = "";
            #if UNITY_IOS && !UNITY_EDITOR
            keyToLook = StoreJSONConsts.MARKETITEM_IOS_ID;
            #elif UNITY_ANDROID && !UNITY_EDITOR
            keyToLook = StoreJSONConsts.MARKETITEM_ANDROID_ID;
            #endif
            if (!string.IsNullOrEmpty(keyToLook) && jsonObject.HasField(keyToLook)) {
                ProductId = jsonObject[keyToLook].str;
            } else {
                ProductId = jsonObject[StoreJSONConsts.MARKETITEM_PRODUCT_ID].str;
            }
            Price = jsonObject[StoreJSONConsts.MARKETITEM_PRICE].n;
            int cOrdinal = System.Convert.ToInt32(((JSONObject)jsonObject[StoreJSONConsts.MARKETITEM_CONSUMABLE]).n);
            if (cOrdinal == 0) {
                this.consumable = Consumable.NONCONSUMABLE;
            } else if (cOrdinal == 1){
                this.consumable = Consumable.CONSUMABLE;
            } else {
                this.consumable = Consumable.SUBSCRIPTION;
            }

            if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICE]) {
                this.MarketPriceAndCurrency = jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICE].str;
            } else {
                this.MarketPriceAndCurrency = "";
            }
            if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETTITLE]) {
                this.MarketTitle = jsonObject[StoreJSONConsts.MARKETITEM_MARKETTITLE].str;
            } else {
                this.MarketTitle = "";
            }
            if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETDESC]) {
                this.MarketDescription = jsonObject[StoreJSONConsts.MARKETITEM_MARKETDESC].str;
            } else {
                this.MarketDescription = "";
            }
            if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE]) {
                this.MarketCurrencyCode = jsonObject[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE].str;
            } else {
                this.MarketCurrencyCode = "";
            }
            if (jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS]) {
                this.MarketPriceMicros = System.Convert.ToInt64(jsonObject[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS].n);
            } else {
                this.MarketPriceMicros = 0;
            }
        }
开发者ID:amisiak7,项目名称:jewels2,代码行数:55,代码来源:MarketItem.cs

示例13: CompareJSONCharacterAttributes

    private bool CompareJSONCharacterAttributes(JSONObject _member, JSONObject _addition)
    {
        Debug.Log("MEMBER: " + _member.ToString());
        Debug.Log("ADD: " + _addition.ToString());
        if(!_member.HasField("characterName") || !_addition.HasField("characterName"))
        {
            Debug.Log("One of these items isn't a JSON character representation.");
            return false;
        }

        if(_member["characterName"].str == _addition["characterName"].str &&
            _member["characterRace"].str == _addition["characterRace"].str &&
            _member["characterClass"].str == _addition["characterClass"].str)
            return true;

        return false;
    }
开发者ID:kingian,项目名称:osric_sandbox,代码行数:17,代码来源:OSRICSaveLoadData.cs

示例14: SendRewardMessage

 public static void SendRewardMessage(JSONObject result, MyMessageScript messageScript, string initialString)
 {
     string rewardString = "";
     if (result.HasField("money"))
     {
         Debug.Log("reward found!");
         float money = result.GetField("money").n;
         string moneyReward = String.Format(StringResources.GetLocalizedString("moneyReward"), money);
         rewardString += moneyReward;
     }
     if (result.HasField("gems"))
     {
         Debug.Log("reward found!");
         float gems = result.GetField("gems").n;
         string gemsReward = String.Format(StringResources.GetLocalizedString("gemsReward"), gems);
         rewardString += gemsReward;
     }
     if (result.HasField("bonus"))
     {
         Debug.Log("reward found!");
         string bonusName = StringResources.GetLocalizedString(result.GetField("bonus").str);
         string bonusReward = String.Format(StringResources.GetLocalizedString("bonusReward"), bonusName);
         rewardString += bonusReward;
     }
     if (result.HasField("tramSkin"))
     {
         Debug.Log("reward found!");
         rewardString += StringResources.GetLocalizedString("tramSkinReward");
     }
     if (result.HasField("conductorSkin"))
     {
         Debug.Log("reward found!");
         rewardString += StringResources.GetLocalizedString("conductorSkinReward");
     }
     if (result.HasField("tramLives"))
     {
         Debug.Log("reward found!");
         float tramLives = result.GetField("tramLives").n;
         rewardString += String.Format(StringResources.GetLocalizedString("tramLivesReward"), tramLives);
     }
     if (rewardString != "")
     {
         initialString += rewardString;
         messageScript.AddMessage(initialString);
     }
 }
开发者ID:Syjgin,项目名称:zerotram,代码行数:46,代码来源:MessageSender.cs

示例15: MarketItem

 /// <summary>
 /// Constructor.
 /// Generates an instance of <c>MarketItem</c> from a <c>JSONObject<c>.
 /// </summary>
 /// <param name="jsonObject">A <c>JSONObject</c> representation of the wanted 
 /// <c>MarketItem</c>.</param>
 public MarketItem(JSONObject jsonObject)
 {
     string keyToLook = "";
     #if UNITY_IOS && !UNITY_EDITOR
     keyToLook = JSONConsts.MARKETITEM_IOS_ID;
     #elif UNITY_ANDROID && !UNITY_EDITOR
     keyToLook = JSONConsts.MARKETITEM_ANDROID_ID;
     #endif
     if (!string.IsNullOrEmpty(keyToLook) && jsonObject.HasField(keyToLook)) {
         ProductId = jsonObject[keyToLook].str;
     } else {
         ProductId = jsonObject[JSONConsts.MARKETITEM_PRODUCT_ID].str;
     }
     Price = jsonObject[JSONConsts.MARKETITEM_PRICE].n;
     int cOrdinal = System.Convert.ToInt32(((JSONObject)jsonObject[JSONConsts.MARKETITEM_CONSUMABLE]).n);
     if (cOrdinal == 0) {
         this.consumable = Consumable.NONCONSUMABLE;
     } else if (cOrdinal == 1){
         this.consumable = Consumable.CONSUMABLE;
     } else {
         this.consumable = Consumable.SUBSCRIPTION;
     }
 }
开发者ID:BenanHamid,项目名称:unity3d-store,代码行数:29,代码来源:MarketItem.cs


注:本文中的JSONObject.HasField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。