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


C# JSONObject类代码示例

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


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

示例1: parseData

 void parseData(string data)
 {
     JSONObject json = new JSONObject (data);
     string action = json.GetField ("action").str;
     print(action + "parse data" + data);
     JSONObject pos = json.GetField("position");
     Single pX = Convert.ToSingle (pos.GetField ("X").str);
     Single pY = Convert.ToSingle (pos.GetField ("Y").str);
     Single pZ = Convert.ToSingle (pos.GetField ("Z").str);
     Vector3 position = new Vector3 (pX, pY, pZ);
     print ("new vector = x-" + pos.GetField ("X").str + " y-" + pos.GetField ("Y").str);
     JSONObject rot = json.GetField("rotation");
     Single rX = Convert.ToSingle (rot.GetField ("X").str);
     Single rY = Convert.ToSingle (rot.GetField ("Y").str);
     Single rZ = Convert.ToSingle (rot.GetField ("Z").str);
     Single rW = Convert.ToSingle (rot.GetField ("W").str);
     Quaternion rotation = new Quaternion (rX, rY, rZ, rW);
     switch (action) {
         case "start":
             this.id = json.GetField ("id").str;
             createPlayer ();
             break;
         case "newPlayer":
             createNewClient (json.GetField ("id").str, position, rotation);
             break;
         case "move":
             moveClient (json.GetField ("id").str, position, rotation);
             break;
     }
 }
开发者ID:Bibazoo,项目名称:UnityClientServer,代码行数:30,代码来源:EventListener.cs

示例2: Update

	// Update is called once per frame
	void Update () {

		lastQ = Input.gyro.attitude;
		lastAcc = Input.acceleration;

		if (Transfering) {

			counter += Time.deltaTime;

						if (counter > updateRate) {
								counter = 0;

								JSONObject json = new JSONObject ();
								json.AddField ("command", "gyro");
								json.AddField ("x", lastQ.x);
								json.AddField ("y", lastQ.y);
								json.AddField ("z", lastQ.z);
								json.AddField ("w", lastQ.w);
								json.AddField ("accX", lastAcc.x);
								json.AddField ("accY", lastAcc.y);
								json.AddField ("accZ", lastAcc.z);
								communicationManager.SendJson (json);


						}

				}

	}
开发者ID:huw12313212,项目名称:GlassGames,代码行数:30,代码来源:GyroManager.cs

示例3: AddScore

 /// <summary>
 /// Adds Score to database
 /// </summary>
 /// <param name="name"></param>
 /// <param name="id"></param>
 /// <param name="score"></param>
 /// <returns></returns>
 private IEnumerator AddScore(string name, string id, string score)
 {
     WWWForm f = new WWWForm();
     f.AddField("ScoreID", id);
     f.AddField("Name", name);
     f.AddField("Point", score);
     WWW w = new WWW("demo/theappguruz/score/add", f);
     yield return w;
     if (w.error == null)
     {
         JSONObject jsonObject = new JSONObject(w.text);
         string data = jsonObject.GetField("Status").str;
         if (data != null && data.Equals("Success"))
         {
             Debug.Log("Successfull");
         }
         else
         {
             Debug.Log("Fatel Error");
         }
     }
     else
     {
         Debug.Log("No Internet Or Other Network Issue" + w.error);
     }
 }
开发者ID:power7714,项目名称:centralized-leader-board-unity-used-personal-web-api,代码行数:33,代码来源:Test.cs

示例4: ToVector4

	public static Vector4 ToVector4(JSONObject obj) {
		float x = obj["x"] ? obj["x"].f : 0;
		float y = obj["y"] ? obj["y"].f : 0;
		float z = obj["z"] ? obj["z"].f : 0;
		float w = obj["w"] ? obj["w"].f : 0;
		return new Vector4(x, y, z, w);
	}
开发者ID:trananh1992,项目名称:3DActionGame,代码行数:7,代码来源:VectorTemplates.cs

示例5: ListStorePage

        public KnetikApiResponse ListStorePage(
            int page = 1,
            int limit = 10,
            List<string> terms = null,
            List<string> related = null,
            bool useCatalog = true,
            Action<KnetikApiResponse> cb = null
        )
        {
            JSONObject j = new JSONObject (JSONObject.Type.OBJECT);
            j.AddField ("page", page);
            j.AddField ("limit", limit);
            if (terms != null) {
                j.AddField ("terms", JSONObject.Create(terms));
            }
            if (related != null) {
                j.AddField ("related", JSONObject.Create(related));
            }
            j.AddField("useCatalog", useCatalog);

            String body = j.Print ();

            KnetikRequest req = CreateRequest(ListStorePageEndpoint, body);

            KnetikApiResponse response = new KnetikApiResponse(this, req, cb);
            return  response;
        }
开发者ID:knetikmedia,项目名称:UnitySDK,代码行数:27,代码来源:Store.cs

示例6: ProcessMyGameStateResponse

        private static void ProcessMyGameStateResponse(JSONObject jsonData)
        {
            if (jsonData.GetField ("gameStates")) {
                JSONObject gameStateData = jsonData.GetField ("gameStates");

                for (int i = 0; i < gameStateData.list.Count; i++) {
                    JSONObject gameState = gameStateData.list [i];

                    string access = null;
                    if (gameState.HasField ("access")) {
                        access = gameState.GetField ("access").str;
                    }

                    string data = null;
                    if (gameState.HasField ("data")) {
                        data = gameState.GetField ("data").str;
                    }

                    if (access != null && data != null) {
                        if (access.Equals ("private")) {
                            PrivateGameStateData = data;
                            SpilUnityImplementationBase.fireGameStateUpdated ("private");
                        } else if (access.Equals ("public")) {
                            PublicGameStateData = data;
                            SpilUnityImplementationBase.fireGameStateUpdated ("public");
                        }
                    }
                }
            }
        }
开发者ID:spilgames,项目名称:spil_event_unity_plugin,代码行数:30,代码来源:GameStateResponse.cs

示例7: accessData

    void accessData(JSONObject obj)
    {
        switch(obj.type){
            case JSONObject.Type.OBJECT:
                for(int i = 0; i < obj.list.Count; i++){
                    string key = (string)obj.keys[i];
                    JSONObject j = (JSONObject)obj.list[i];
                    Debug.Log(key);
                    accessData(j);
                }
                break;
            case JSONObject.Type.ARRAY:
                foreach(JSONObject j in obj.list){
                    accessData(j);
                }
                break;
            case JSONObject.Type.STRING:
                Debug.Log(obj.str);
                break;
            case JSONObject.Type.NUMBER:
                Debug.Log(obj.n);
                break;
            case JSONObject.Type.BOOL:
                Debug.Log(obj.b);
                break;
            case JSONObject.Type.NULL:
                Debug.Log("NULL");
                break;

        }
    }
开发者ID:Ruixel,项目名称:CYplayer,代码行数:31,代码来源:worldGen.cs

示例8: ToVector3

 public static Vector3 ToVector3(JSONObject obj)
 {
     float x = obj["x"] ? obj["x"].f : 0;
     float y = obj["y"] ? obj["y"].f : 0;
     float z = obj["z"] ? obj["z"].f : 0;
     return new Vector3(x, y, z);
 }
开发者ID:kibotu,项目名称:unity-socket.io,代码行数:7,代码来源:VectorTemplates.cs

示例9: Update

    public void Update()
    {
        if (dataLoaded || currencyWWW == null || !currencyWWW.isDone) return;

        // let's look at the results
        JSONObject j = new JSONObject(currencyWWW.text);

        j.GetField("list", delegate (JSONObject list) {

            list.GetField("resources", delegate (JSONObject resources) {
                foreach (JSONObject entry in resources.list)
                {
                    entry.GetField("resource", delegate (JSONObject resource) {
                        resource.GetField("fields", delegate (JSONObject fields) {
                            string name;
                            string price;
                            string volume;

                            fields.GetField(out price, "price", "-1");
                            fields.GetField(out name, "name", "NONAME");
                            fields.GetField(out volume, "volume", "NOVOLUME");

                            CurrencyData data = new CurrencyData(name, price, volume);
                            CreateDataObject(data);

                            //Debug.Log("Found : " + name + " = " + float.Parse(price) + " at " + float.Parse(volume) + " sold");
                        });
                    });
                }
                dataLoaded = true;
            });
        }, delegate (string list) { //"name" will be equal to the name of the missing field.  In this case, "hits"
            Debug.LogWarning("no data found");
        });
    }
开发者ID:waltzaround,项目名称:CTEC608-Data-Visualisation,代码行数:35,代码来源:data.cs

示例10: OnPlayAvariable

    private void OnPlayAvariable(SocketIOEvent evt )
    {
        UserData player1 = CheckPlayer(evt.data.GetField("player1"));
        UserData player2 = CheckPlayer(evt.data.GetField("player2"));

        if( GameManager.Instance.userData.ID == player1.ID ){
            Debug.Log("Player1 Ready!!");
            GameManager.Instance.player = GameManager.Player.player1;

            JSONObject ready = new JSONObject();
            ready.AddField("id", player1.ID );
            NetworkManager.Instance.Socket.Emit("READY", ready);
        }else{
            if( GameManager.Instance.userData.ID == player2.ID ){
                Debug.Log("Player2 Ready!!");
                GameManager.Instance.player = GameManager.Player.player2;
                JSONObject ready = new JSONObject();
                ready.AddField("id", player1.ID );
                NetworkManager.Instance.Socket.Emit("READY", ready);
            }else{
                Debug.Log("JUST WATCH!!");
                GameManager.Instance.player = GameManager.Player.guest;
            }
        }

        oldText.text 		= player1.UserName;
        friendText.text 	= player2.UserName;
    }
开发者ID:shunlll999,项目名称:pong-unity,代码行数:28,代码来源:GameController.cs

示例11: fromJSONObject

	public void fromJSONObject(JSONObject json)
	{
		JSONObject marketItem = json.GetField("marketItem");

		JSONObject jsonProductId = marketItem.GetField("productId");
		if (jsonProductId != null) {
			this.productId = marketItem.GetField("productId").str;
		} else {
			this.productId = "";
		}
        
		JSONObject jsonIosId = marketItem.GetField ("iosId");

		this.useIos = (jsonIosId != null);
		if (this.useIos)
		{
			this.iosId = jsonIosId.str;
		}
		
		JSONObject jsonAndroidId = marketItem.GetField ("androidId");
		this.useAndroid = (jsonAndroidId != null);
		if (this.useAndroid)
		{
			this.androidId = jsonAndroidId.str;
		}
		
		this.price = marketItem.GetField ("price").f;
		this.consumable = (Consumable)int.Parse(marketItem.GetField("consumable").ToString());
	}
开发者ID:Bakiet,项目名称:UnityZombieCross,代码行数:29,代码来源:EconomyBuilderData.cs

示例12: ParseFrom

    public Dictionary<string, string> ParseFrom(string rawdata)
    {
        JSONObject jsonObj = new JSONObject(rawdata);
        Dictionary<string, string> data = jsonObj.ToDictionary();

        return data;
    }
开发者ID:rmarx,项目名称:ReverseRPG,代码行数:7,代码来源:LugusConfigDataHelper.cs

示例13: Buy

        /// <summary>
        /// Buys the purchasable virtual item.
        /// Implementation in subclasses will be according to specific type of purchase.
        /// </summary>
        /// <param name="payload">a string you want to be assigned to the purchase. This string
        /// is saved in a static variable and will be given bacl to you when the
        ///  purchase is completed.</param>
        /// <exception cref="Soomla.Store.InsufficientFundsException">throws InsufficientFundsException</exception>
        public override void Buy(string payload)
        {
            SoomlaUtils.LogDebug("SOOMLA PurchaseWithVirtualItem", "Trying to buy a " + AssociatedItem.Name + " with "
                                 + Amount + " pieces of " + TargetItemId);

            VirtualItem item = getTargetVirtualItem ();
            if (item == null) {
                return;
            }

            JSONObject eventJSON = new JSONObject();
            eventJSON.AddField("itemId", AssociatedItem.ItemId);
            StoreEvents.Instance.onItemPurchaseStarted(eventJSON.print(), true);

            if (!checkTargetBalance (item)) {
                StoreEvents.OnNotEnoughTargetItem(StoreInfo.VirtualItems["seed"]);
                return;
            //				throw new InsufficientFundsException (TargetItemId);
            }

            item.Take(Amount);

            AssociatedItem.Give(1);

            // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events.
            StoreEvents.Instance.RunLater(() => {
                eventJSON = new JSONObject();
                eventJSON.AddField("itemId", AssociatedItem.ItemId);
                eventJSON.AddField("payload", payload);
                StoreEvents.Instance.onItemPurchased(eventJSON.print(), true);
            });
        }
开发者ID:amisiak7,项目名称:jewels2,代码行数:40,代码来源:PurchaseWithVirtualItem.cs

示例14: OSRICAttributeModel

    public OSRICAttributeModel(RPGCharacterModel _cm, JSONObject _jo)
    {
        cm = _cm;
        CharacterModifiers = new OSRICModifierCollection();
        characterName = _jo["characterName"].str;
        Str = (int)_jo["Str"].n;
        Dex = (int)_jo["Dex"].n;
        Con = (int)_jo["Con"].n;
        Int = (int)_jo["Int"].n;
        Wis = (int)_jo["Wis"].n;
        Cha = (int)_jo["Cha"].n;
        hitPoints = (int)_jo["hitPoints"].n;

        string[] levelStr = _jo["level"].str.Split('/');
        level = new int[levelStr.Length];

        for(int i=0; i<levelStr.Length; i++)
            level[i] = Int32.Parse(levelStr[i]);

        experiencePoints = (int)_jo["experiencePoints"].n;
        vision = (int)_jo["vision"].n;
        move = (int)_jo["move"].n;
        characterGender = OSRICConstants.GetEnum<OSRIC_GENDER>(_jo["characterGender"].str);
        characterRace = OSRICConstants.GetEnum<OSRIC_RACE>(_jo["characterRace"].str);
        characterClass = OSRICConstants.GetEnum<OSRIC_CLASS>(_jo["characterClass"].str);
        characterAlignment = OSRICConstants.GetEnum<OSRIC_ALIGNMENT>(_jo["characterAlignment"].str);
        characterState = OSRICConstants.GetEnum<OSRIC_CHARACTER_STATE>(_jo["characterState"].str);
        foreach(JSONObject obj in _jo["CharacterModifiers"].list)
            CharacterModifiers.Add(new OSRICCharacterModifier(obj));
    }
开发者ID:kingian,项目名称:osric_sandbox,代码行数:30,代码来源:OSRICAttributeModel.cs

示例15: SetResults

  public void SetResults(JSONObject jsonData) {
		spinDataResult = jsonData;
    resultsData = jsonData.GetArray("items");
    winningGold = jsonData.GetArray("wGold");
		// Calculate extra data (winning type, winning count from list result items)
		JSONObject extraData = SlotCombination.CalculateCombination(resultsData, GetNumLine());
    winningCount = extraData.GetArray("wCount");
    winningType = extraData.GetArray("wType");
		//
    isJackpot = jsonData.GetBoolean("isJP");
		freeSpinLeft = jsonData.GetInt("frLeft");
		isBigWin = jsonData.GetBoolean("bWin");
		gotFreeSpin = jsonData.GetInt("frCount") > 0;
		// bool[] winingItems = new bool[15];
		// for (int i = 0; i < winningGold.Length; i++) {
		// 	if (winningGold[i].Number > 0) {
		// 		for (int j = 0; j < SlotCombination.NUM_REELS; j++) {
		// 			winingItems[SlotCombination.COMBINATION[i, j]] = true;
		// 		}
		// 	}
		// }
    for (int i = 0; i < slotReels.Length; i++) {
      slotReels[i].SetResults(new int[3] { (int)resultsData[i * 3].Number, (int)resultsData[i * 3 + 1].Number, (int)resultsData[i * 3 + 2].Number });
    }
  }
开发者ID:markofevil3,项目名称:SlotMachine,代码行数:25,代码来源:SlotMachine.cs


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