當前位置: 首頁>>代碼示例>>C#>>正文


C# JSONArray.Add方法代碼示例

本文整理匯總了C#中SimpleJSON.JSONArray.Add方法的典型用法代碼示例。如果您正苦於以下問題:C# JSONArray.Add方法的具體用法?C# JSONArray.Add怎麽用?C# JSONArray.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleJSON.JSONArray的用法示例。


在下文中一共展示了JSONArray.Add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ToJSON

	//JSON Format:

	/*
	{
		"session": {
			"id": "session1234",
			"player": "user123",
			"game": "game1",
			"version": "version 1.0"
		},
		
		"play_events" :
		[ 
		{  "time": "2015-02-17T22:43:45-5:00", "event": "PowerUp.FireBall", "value": "1.0", "level": "1-1"},
		{  "time": "2015-02-17T22:45:45-5:00", "event": "PowerUp.Mushroom", "value": "2.0", "level": "1-1"}
		 ]
	}
	*/

	public static string ToJSON(Gloggr_Report r)
	{
	
		JSONNode n = new JSONClass();
		
		
		
		n.Add ("session",  Gloggr_SessionHeader.ToJSONObject(r.session)  );
		
		JSONArray a = new JSONArray();
		
		foreach(Gloggr_PlayEvent e in r.play_events)
		{
			a.Add(Gloggr_PlayEvent.ToJSONObject(e));
		}
		
		n.Add ("play_events", a);
		
		return n.ToString();	
	
//		string json = JsonConvert.SerializeObject(e, Formatting.Indented);
//		//from Gloggr_SessionHeader.ToJSON
//		//json = Gloggr_SessionHeader.FormatJSONKeys(json);
//		//from Gloggr_PlayEvent.ToJSON
//		//json = Gloggr_PlayEvent.FormatJSONKeys(json);
//		return json;
	}
開發者ID:game-design,項目名稱:independent-study,代碼行數:46,代碼來源:Gloggr_Report.cs

示例2: convertPersistentListToJSONArray

				public static JSONArray convertPersistentListToJSONArray (List<JSONPersistent> list)
				{		
						JSONArray jArray = new JSONArray ();
		
						foreach (JSONPersistent persist in list) {
								jArray.Add (persist.getDataClass ());
						}

						return jArray;
				}
開發者ID:DomDomHaas,項目名稱:JSONPersistency,代碼行數:10,代碼來源:JSONPersistentArray.cs

示例3: Add

		public override void Add (JSONNode aItem)
		{
			var tmp = new JSONArray ();
			tmp.Add (aItem);
			Set (tmp);
		}
開發者ID:MirandaDora,項目名稱:mbc,代碼行數:6,代碼來源:SimpleJSON.cs

示例4: Deserialize

		public static JSONNode Deserialize (System.IO.BinaryReader aReader)
		{
			JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte ();
			switch (type) {
			case JSONBinaryTag.Array:
			{
				int count = aReader.ReadInt32 ();
				JSONArray tmp = new JSONArray ();
				for (int i = 0; i < count; i++)
					tmp.Add (Deserialize (aReader));
				return tmp;
			}
			case JSONBinaryTag.Class:
			{
				int count = aReader.ReadInt32 ();                
				JSONClass tmp = new JSONClass ();
				for (int i = 0; i < count; i++) {
					string key = aReader.ReadString ();
					var val = Deserialize (aReader);
					tmp.Add (key, val);
				}
				return tmp;
			}
			case JSONBinaryTag.Value:
			{
				return new JSONData (aReader.ReadString ());
			}
			case JSONBinaryTag.IntValue:
			{
				return new JSONData (aReader.ReadInt32 ());
			}
			case JSONBinaryTag.DoubleValue:
			{
				return new JSONData (aReader.ReadDouble ());
			}
			case JSONBinaryTag.BoolValue:
			{
				return new JSONData (aReader.ReadBoolean ());
			}
			case JSONBinaryTag.FloatValue:
			{
				return new JSONData (aReader.ReadSingle ());
			}
				
			default:
			{
				throw new Exception ("Error deserializing JSON. Unknown tag: " + type);
			}
			}
		}
開發者ID:MirandaDora,項目名稱:mbc,代碼行數:50,代碼來源:SimpleJSON.cs

示例5: SaveToJSON

    private static JSONNode SaveToJSON()
    {
        JSONClass root = new JSONClass ();

        JSONArray slotsJson = new JSONArray ();
        int i =0;
        foreach (Save slotInList in saves) {
            JSONClass slot = new JSONClass();

            if(saves[i].Hero.Name != null) {
                JSONData name = new JSONData (slotInList.Hero.Name);
                slot.Add ("name", name);
                JSONData score = new JSONData (slotInList.Score);
                slot.Add ("score", score);
                JSONData heroClass = new JSONData (slotInList.Hero.GetType().ToString());
                slot.Add ("class", heroClass);
                JSONData heroXp = new JSONData (slotInList.Hero.XpQuantity);
                slot.Add ("xp", heroXp);
                JSONData currentLevel = new JSONData (GameModel.Levels[slotInList.LevelId].Name);
                slot.Add ("currentLevel", currentLevel);
            } else {
                slot.Add ("name", "");
                slot.Add ("score", "");
                slot.Add ("class", "");
                slot.Add ("xp", "");
                slot.Add ("currentLevel", "");
            }

            slotsJson.Add (slot);

            Debug.Log(i);
            i++;
        }

        root.Add ("slots", slotsJson);
        return root;
    }
開發者ID:ifgx,項目名稱:scripts-spr3,代碼行數:37,代碼來源:SaveParser.cs

示例6: JSONLazyCreator

		public override JSONNode this [int aIndex]
		{
			get {
				return new JSONLazyCreator (this);
			}
			set {
				var tmp = new JSONArray ();
				tmp.Add (value);
				Set (tmp);
			}
		}
開發者ID:MirandaDora,項目名稱:mbc,代碼行數:11,代碼來源:SimpleJSON.cs

示例7: GetExtJson

        /*
         * {
                "type": "group_info", //標記
                "group": //group 信息
                 {
                    "member":
                    [//成員
                        {
                            "uid": ""//用戶id
                        },
                        ...
                    ],
                    "vid": "", //場館id
                    "name": "",//..名字
                    "address": "",//..地址
                    "time": "",//..時間
                    "latitude": "",//..經度
                    "longtitude": "",//..緯度
                    "state": "",//..狀態 3種狀態 0 是未預訂 2是預訂 1是投票狀態
                    "max": ""//..最大成員數 默認10
                }
            }
         */
        public string GetExtJson(string groupID)
        {
            Monitor.Enter(userGroupDict);
            try
            {
                SportMatchGroup group = groupList.Find(a => { return a.groupID == groupID; });
                Venue venue = group.venue;

                JSONClass jc = new JSONClass();
                jc.Add("type", new JSONData("group_info"));
                JSONClass jc_1 = new JSONClass();
                JSONArray ja_1_1 = new JSONArray();
                var itr = userGroupDict.GetEnumerator();
                while (itr.MoveNext())
                {
                    string groupid = itr.Current.Value;
                    if (groupid != groupID)
                        continue;
                    string uuid = itr.Current.Key;
                    JSONClass jc_1_1_i = new JSONClass();
                    jc_1_1_i.Add("uid", new JSONData(uuid));
                    ja_1_1.Add(jc_1_1_i);
                }
                jc_1.Add("member", ja_1_1);
                if (venue == null)
                {
                    jc_1.Add("vid", new JSONData(""));
                    jc_1.Add("name", new JSONData(""));
                    jc_1.Add("address", new JSONData(""));
                    jc_1.Add("time", new JSONData(""));
                    jc_1.Add("latitude", new JSONData(""));
                    jc_1.Add("longtitude", new JSONData(""));
                    jc_1.Add("state", new JSONData(0));
                }
                else
                {
                    jc_1.Add("vid", new JSONData(venue.id));
                    jc_1.Add("name", new JSONData(venue.name));
                    jc_1.Add("address", new JSONData(venue.address));
                    jc_1.Add("time", new JSONData(venue.time));
                    jc_1.Add("latitude", new JSONData(venue.latitude));
                    jc_1.Add("longtitude", new JSONData(venue.longitude));
                    jc_1.Add("state", new JSONData(2));
                }
                jc_1.Add("max", new JSONData(10));
                jc.Add("group", jc_1);
                return jc.ToJSON(0);
            }
            finally
            {
                Monitor.Exit(userGroupDict);
            }
        }
開發者ID:y85171642,項目名稱:ESportServer,代碼行數:76,代碼來源:SportMatchManager.cs

示例8: WordOut

    //Send completed action
    public void WordOut(WordActionGenerator.WordAction action) {
		if (sendLimit < sendCounter) {
			//Debug.LogWarning(action.ToString() + " out");

			#if UNITY_ANDROID
			Handheld.Vibrate();
			#endif

			JSONNode data = new JSONClass();

			//Get script containing words and actions
			UI_phonescreen_script uiPhoneScreenScript = GameObject.Find("UI_phonescreen").GetComponent<UI_phonescreen_script>();
			JSONArray arrayToSend = new JSONArray();

			//Get words that match performed action
			for (int i = 0; i < uiPhoneScreenScript.words.Count; i++)
			{
				if (uiPhoneScreenScript.words[i].action == action)
				{
					JSONNode wordActionPair = new JSONClass();
					wordActionPair["word"] = uiPhoneScreenScript.words[i].word;
					wordActionPair["action"].AsInt = (int)uiPhoneScreenScript.words[i].action;

					arrayToSend.Add(wordActionPair);
				}
			}

			data["id"] = id;
			data["function"] = "wordOut";
			data["words"] = arrayToSend;

			udpSend.Send(data);

			sendCounter = 0;
		}

    }
開發者ID:Urauth,項目名稱:Finnish-Game-Jam-2016,代碼行數:38,代碼來源:ClientNetworker.cs

示例9: SendMessage

        /*
         *{
                "target_type":"users",     // users 給用戶發消息。chatgroups 給群發消息,chatrooms 給聊天室發消息
                "target":["testb","testc"], // 注意這裏需要用數組,數組長度建議不大於20,即使隻有
                                            // 一個用戶u1或者群組,也要用數組形式 ['u1'],給用戶發
                                            // 送時數組元素是用戶名,給群組發送時數組元素是groupid
                "msg":{  //消息內容
                    "type":"txt",  // 消息類型,不局限與文本消息。任何消息類型都可以加擴展消息
                    "msg":"消息"    // 隨意傳入都可以
                },
                "from":"testa",  //表示消息發送者。無此字段Server會默認設置為"from":"admin",有from字段但值為空串("")時請求失敗
                "ext":{   //擴展屬性,由APP自己定義。可以沒有這個字段,但是如果有,值不能是"ext:null"這種形式,否則出錯
                    "attr1":"v1"   // 消息的擴展內容,可以增加字段,擴展消息主要解析不分。
                }
            }
         */
        public string SendMessage(string targetType, string[] targetID, string msgType, string msgText, string fromUUID, string extJson = null)
        {
            JSONClass jc = new JSONClass();
            jc.Add("target_type", JD(targetType));
            JSONArray ja = new JSONArray();
            foreach (string tID in targetID)
            {
                ja.Add(JD(tID));
            }
            jc.Add("target", ja);
            JSONClass jmsg = new JSONClass();
            jmsg.Add("type", JD(msgType));
            jmsg.Add("msg", JD(msgText));
            jc.Add("msg", jmsg);
            if (fromUUID != null)
                jc.Add("from", fromUUID);
            if (extJson != null)
                jc.Add("ext", JSON.Parse(extJson));

            string postData = jc.ToJSON(0);
            string result = ReqUrl(easeMobUrl + "messages", "POST", postData, token);
            return result;
        }
開發者ID:y85171642,項目名稱:ESportServer,代碼行數:39,代碼來源:EaseXin.cs

示例10: HighScoreToJSON

    private static JSONNode HighScoreToJSON()
    {
        JSONClass root = new JSONClass ();

        JSONArray slotsJson = new JSONArray ();
        foreach (HighScore slotInList in highScores) {
            JSONClass slot = new JSONClass();

            JSONData name = new JSONData (slotInList.Name);
            slot.Add ("name", name);

            JSONData score = new JSONData (slotInList.Score);
            slot.Add ("score", score);

            slotsJson.Add (slot);
        }

        root.Add ("slots", slotsJson);
        return root;
    }
開發者ID:ifgx,項目名稱:scripts-spr3,代碼行數:20,代碼來源:HighScoreParser.cs

示例11: SaveXBuildData

    public void SaveXBuildData(string IMG_DATA, string start_code, string update_code)
    {
        XDebug.Log ("Begining save..");
        XBuildData xbuild = DPS.XBD;

        JSONArray json = new JSONArray ();
        JSONArray names = new JSONArray ();
        if (xbuild.names != null) {
            for (int i = 0; i < xbuild.names.GetLength(0); i++) {
                JSONArray nameline = new JSONArray ();
                for (int j = 0; j < xbuild.names.GetLength(1); j++) {
                    if (xbuild.names [i, j] != null)
                        nameline.Add (xbuild.names [i, j]);
                    else
                        nameline.Add ("null");
                }
                names.Add (nameline);
            }
        }
        json.Add("names", names);

        JSONArray types = new JSONArray ();
        if (xbuild.types != null) {
            for (int i = 0; i < xbuild.types.GetLength(0); i++) {
                JSONArray typeline = new JSONArray ();
                for (int j = 0; j < xbuild.types.GetLength(1); j++) {
                    if (xbuild.types [i, j] != null)
                        typeline.Add (xbuild.types [i, j] + "");
                    else
                        typeline.Add ("0");
                }
                types.Add (typeline);
            }
        }
        json.Add("types", types);

        json.Add("center_x", new JSONData(xbuild.center.x));
        json.Add("center_y", new JSONData(xbuild.center.y));

        XDebug.Log ("Saving... @id" + xbuild.db_id + " " + json.ToString());
        XDebug.Log ("Start code: \n" + start_code);
        XDebug.Log ("Update Code: \n" + update_code);

        //XDebug.Log ("Image data size: \n" + IMG_DATA.Length);
        Application.ExternalCall ("SaveXBuild", xbuild.db_id, xbuild.name, json.ToString (), IMG_DATA, start_code, update_code);
    }
開發者ID:thundercraker,項目名稱:XBuilder,代碼行數:46,代碼來源:DatabaseAdapter.cs

示例12: Serialize

        public static void Serialize(JSONClass jc, object obj, bool serializeStatic = false)
        {
            foreach (FieldInfo mi in obj.GetType().GetFields())
            {
                if (mi.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0)
                    continue;

                if (!serializeStatic && mi.IsStatic)
                    continue;

                if (mi.FieldType.IsArray)
                {
                    IEnumerable arrobjs = (IEnumerable)mi.GetValue(obj);

                    JSONArray arr = new JSONArray();

                    if (typeof(IJSONSerializable).IsAssignableFrom(mi.FieldType.GetElementType()))
                    {
                        foreach (object aobj in arrobjs)
                        {
                            JSONClass cls = new JSONClass();
                            ((IJSONSerializable)aobj).OnSerialize(cls);
                            arr.Add(cls);
                        }
                    }
                    else
                    {
                        if (mi.FieldType.GetElementType() == typeof(GameObject))
                        {
                            foreach (object aobj in arrobjs)
                            {
                                arr.Add(AssetUtility.GetAssetPath((GameObject)aobj));
                            }
                        }
                        else
                        {
                            foreach (object aobj in arrobjs)
                            {
                                arr.Add(aobj.ToString());
                            }
                        }
                    }
                    jc[mi.Name] = arr;

                }
                else
                {
                    if (typeof(IJSONSerializable).IsAssignableFrom(mi.FieldType))
                    {
                        JSONClass cls = new JSONClass();
                        (mi.GetValue(obj) as IJSONSerializable).OnSerialize(cls);
                        jc[mi.Name] = cls;
                    }
                    else
                    {
                        if (mi.FieldType == typeof(GameObject))
                        {
                            jc[mi.Name] = AssetUtility.GetAssetPath((GameObject)mi.GetValue(obj));
                        }
                        else if (mi.FieldType == typeof(Color))
                        {
                            Color c = (Color)mi.GetValue(obj);
                            jc[mi.Name] = SerializeColor(c);
                        }
                        else if (mi.FieldType == typeof(Vector4))
                        {
                            Vector4 c = (Vector4)mi.GetValue(obj);
                            jc[mi.Name] = SerializeVector4(c);
                        }
                        else if (mi.FieldType == typeof(Vector3))
                        {
                            Vector3 c = (Vector3)mi.GetValue(obj);
                            jc[mi.Name] = SerializeVector3(c);
                        }
                        else if (mi.FieldType == typeof(Vector2))
                        {
                            Vector2 c = (Vector2)mi.GetValue(obj);
                            jc[mi.Name] = SerializeVector2(c);
                        }
                        else if (mi.FieldType == typeof(TimeSpan))
                        {
                            jc[mi.Name] = ((TimeSpan)mi.GetValue(obj)).ToString();
                        }
                        else if(mi.FieldType.IsEnum)
                        {
                            Enum v = (Enum)mi.GetValue(obj);
                            jc[mi.Name] = string.Format("{0} {1}", v.GetType().Name, v.ToString());
                        }
                        else
                        {
                            object v = mi.GetValue(obj);
                            if (mi.FieldType == typeof(string))
                                v = "";

                            if (v != null)
                                jc[mi.Name] = mi.GetValue(obj).ToString();
                            else
                                Debug.LogError("[JSONSerialization] Cannot save field: " + mi.Name + " due to its (null)");
                        }
                    }
//.........這裏部分代碼省略.........
開發者ID:RollySeth,項目名稱:MagicaVoxelUnity,代碼行數:101,代碼來源:ISerializable.cs

示例13: Update

	void Update() {
		if (dummyMessageTimer >= 0) {
			if(Mathf.Abs(dummyMessageTimer - Time.time) >= 0.3f) {
				string msgJson = "MESG{\"channel_id\": \"0\", \"message\": \"Dummy Text on Editor Mode - " + Time.time + "\", \"user\": {\"image\": \"http://url\", \"name\": \"Sender\"}, \"ts\": 1418979273365, \"scrap_id\": \"\"}";
				_OnMessageReceived(msgJson);
				dummyMessageTimer = Time.time;
			}
		}

		if (dummyChannelListFlag1) {
			dummyChannelListFlag1 = false;
			JSONClass root = new JSONClass();

			JSONArray channels = new JSONArray();
			JSONClass channel = new JSONClass();

			channel.Add ("id", new JSONData(1));
			channel.Add ("channel_url", new JSONData("app_prefix.channel_url"));
			channel.Add ("name", new JSONData("Sample"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			channel.Add ("id", new JSONData(2));
			channel.Add ("channel_url", new JSONData("app_prefix.Unity3d"));
			channel.Add ("name", new JSONData("Unity3d"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			channel.Add ("id", new JSONData(3));
			channel.Add ("channel_url", new JSONData("app_prefix.Lobby"));
			channel.Add ("name", new JSONData("Lobby"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			channel.Add ("id", new JSONData(4));
			channel.Add ("channel_url", new JSONData("app_prefix.Cocos2d"));
			channel.Add ("name", new JSONData("Cocos2d"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			channel.Add ("id", new JSONData(5));
			channel.Add ("channel_url", new JSONData("app_prefix.GameInsight"));
			channel.Add ("name", new JSONData("GameInsight"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			root.Add ("has_next", new JSONData(true));
			root.Add ("channels", channels);

			_OnQueryChannelList(root.ToString());
		}

		if (dummyChannelListFlag2) {
			dummyChannelListFlag2 = false;
			JSONClass root = new JSONClass();
			
			JSONArray channels = new JSONArray();
			JSONClass channel = new JSONClass();

			channel.Add ("id", new JSONData(6));
			channel.Add ("channel_url", new JSONData("app_prefix.iOS"));
			channel.Add ("name", new JSONData("iOS"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());
			
			channel.Add ("id", new JSONData(7));
			channel.Add ("channel_url", new JSONData("app_prefix.Android"));
			channel.Add ("name", new JSONData("Android"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			channel.Add ("id", new JSONData(8));
			channel.Add ("channel_url", new JSONData("app_prefix.News"));
			channel.Add ("name", new JSONData("News"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			channel.Add ("id", new JSONData(9));
			channel.Add ("channel_url", new JSONData("app_prefix.Lobby"));
			channel.Add ("name", new JSONData("Lobby"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			channel.Add ("id", new JSONData(10));
			channel.Add ("channel_url", new JSONData("app_prefix.iPad"));
			channel.Add ("name", new JSONData("iPad"));
			channel.Add ("cover_img_url", new JSONData("http://localhost/image.jpg"));
			channel.Add ("member_count", new JSONData(999));
			channels.Add(channel.ToString());

			root.Add ("has_next", new JSONData(false));
//.........這裏部分代碼省略.........
開發者ID:smilefam,項目名稱:sendbird-unity-sample,代碼行數:101,代碼來源:SendBird.cs

示例14: ConvertListToJson

        private string ConvertListToJson(List<String> list)
        {
            if (list == null) {
                return null;
            }

            var jsonArray = new JSONArray ();

            foreach (var listItem in list) {
                jsonArray.Add (new JSONData (listItem));
            }

            return jsonArray.ToString ();
        }
開發者ID:tengontheway,項目名稱:unity_sdk,代碼行數:14,代碼來源:AdjustiOS.cs

示例15: toJson

        public JSONClass toJson()
        {
            JSONClass json = new JSONClass ();

            if(versionId != "") 	json.Add ("_id", versionId);
            if(alias != "") 		json.Add ("alias", alias);
            if(gameId != "") 		json.Add ("gameId", gameId);
            if(progress != "") 		json.Add ("progress", progress);
            if(score != "") 		json.Add ("score", score);
            if(trackingCode != "") 	json.Add ("trackingCode", trackingCode);

            json.Add ("maxScore", new JSONData (maxScore));

            JSONArray ws = new JSONArray ();
            foreach (Warning w in warnings) {
                ws.Add (w.toJson());
            }

            json.Add ("warnings", ws);

            return json;
        }
開發者ID:Synpheros,項目名稱:eAdventure4Unity,代碼行數:22,代碼來源:RageWindow.cs


注:本文中的SimpleJSON.JSONArray.Add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。