void Start() { var proj = new SimpleJSON.JSONArray(); var n = new JSONData("item6"); proj.Add(n); n = new JSONData("item18"); proj.Add(n); n = new JSONData("item60"); proj.Add(n); var str = proj.ToString(); Debug.LogError(str); SimpleIAP.GetInstance().LoadProducst(str); }
public SimpleJSON.JSONArray GetProperties() { CleanGroups(); SimpleJSON.JSONArray allGroups = new SimpleJSON.JSONArray(); // SimpleJSON.JSONClass N = new SimpleJSON.JSONClass(); foreach (List <UserEditableObject> gr in groups) { SimpleJSON.JSONArray uuids = new SimpleJSON.JSONArray(); // List<int> uuids = new List<int>(); foreach (UserEditableObject ueo in gr) { SimpleJSON.JSONClass n = new SimpleJSON.JSONClass(); // Debug.Log("adding;"+ueo.GetUuid()); // n["uuid"] = new SimpleJSON.JSONClass(); n["uuid"].AsInt = ueo.GetUuid(); uuids.Add(n); } // SimpleJSON.JSONClass item = new SimpleJSON.JSONClass(); allGroups.Add(uuids); } if (debug) { Debug.Log("allgrou:" + allGroups.ToString()); } return(allGroups); }
//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; }
public static JSONArray convertPersistentListToJSONArray (List<JSONPersistent> list) { JSONArray jArray = new JSONArray (); foreach (JSONPersistent persist in list) { jArray.Add (persist.getDataClass ()); } return jArray; }
public void WriteJson(SimpleJSON.JSONClass jobj) { var abPath = path.Replace("/", "_"); var ls = new SimpleJSON.JSONArray(); foreach (var dep in dependency) { ls.Add(dep.Replace("/", "_")); } jobj.Add(abPath, ls); }
void OnGUI() { if (GUI.Button(new Rect(200, 200, 100, 100), "GetList")) { //Debug.LogError("itemList "+MyStoreAsset.Instance.allItems.Count); var proj = new SimpleJSON.JSONArray(); var n = new JSONData("item6"); proj.Add(n); n = new JSONData("item18"); proj.Add(n); n = new JSONData("item60"); proj.Add(n); var str = proj.ToString(); Debug.LogError(str); SimpleIAP.GetInstance().LoadProducst(str); } if (GUI.Button(new Rect(100, 100, 100, 100), "BuyItem")) { //Soomla.Store.SoomlaStore.BuyMarketItem("item8", "buy item8"); SimpleIAP.GetInstance().ChargeItem("item6"); } }
public virtual SimpleJSON.JSONArray GetAmmoJson() { // (most) gadgets do not serialize their ammo in inventory so this function is needed for them to preserve ammo during level instance loads SimpleJSON.JSONArray N = new SimpleJSON.JSONArray(); foreach (Ammo a in GetAmmo()) { SimpleJSON.JSONClass item = new SimpleJSON.JSONClass(); item[Fraction.numeratorKey].AsInt = a.ammoValue.numerator; item[Fraction.denominatorKey].AsInt = a.ammoValue.denominator; N.Add(item); } return(N); }
SimpleJSON.JSONArray GetListOfDeactivatedCubesAsArray() { int i = 0; SimpleJSON.JSONArray ar = new SimpleJSON.JSONArray(); foreach (DanMeyerCube dmc in cubes) { if (dmc.cubeActive == false) { ar.Add(JsonUtil.IntVector3ToString(dmc.indexedPosition)); } } return(ar); }
public SimpleJSON.JSONArray SerializeUserEditableObjects(List <UserEditableObject> ueos, SceneSerializationType serializationType = SceneSerializationType.Class) { WebGLComm.inst.Debug("<color=#09f>Saver:</color>.SerializeUserEditableObjects()"); SimpleJSON.JSONArray objs = new SimpleJSON.JSONArray(); // Will be a list of objects foreach (UserEditableObject ueo in ueos) { SimpleJSON.JSONClass obj = new SimpleJSON.JSONClass(); // Create a separate json sub-tree of user placed objects, which will be added to the main json after it's populated. obj = JsonUtil.GetUeoBaseProps(obj, ueo, serializationType); objs.Add(obj); } return(objs); }
public static JSONNode ParseCSV(string csvString) { JSONNode output = new JSONArray(); var lines = Regex.Split(csvString, LINE_SPLIT_RE); if (lines.Length <= 1) { return(null); } var header = Regex.Split(lines[0], SPLIT_RE); for (var i = 1; i < lines.Length; i++) { JSONObject obj = new JSONObject(); var values = Regex.Split(lines[i], SPLIT_RE); if (values.Length == 0 || values[0] == "") { continue; } for (var j = 0; j < header.Length && j < values.Length; j++) { string value = values[j]; value = value.TrimStart(TRIM_CHARS).TrimEnd(TRIM_CHARS).Replace("\\", ""); obj.Add(header[j], new JSONString(value)); } output.Add(obj); } return(output); }
//public List<string> ListToSend = new List<string>(); public void GameLoop(object p_callbackResponseTurn) { if (CURRENT_STATE == GameState.REQUEST_TURN) { P1.TurnSend = false; P2.TurnSend = false; var TempWalkP1 = new Dictionary <int, List <string> >(); var List_TempWalkP1 = new List <string>(); TempWalkP1.Add(1, List_TempWalkP1); TempWalkP1.Add(2, List_TempWalkP1); TempWalkP1.Add(3, List_TempWalkP1); var TempDefP1 = new Dictionary <int, List <string> >(); var ListTempDefP1 = new List <string>(); TempDefP1.Add(1, ListTempDefP1); TempDefP1.Add(2, ListTempDefP1); TempDefP1.Add(3, ListTempDefP1); var TempAtkP1 = new Dictionary <int, List <string> >(); var ListTempAtkP1 = new List <string>(); TempAtkP1.Add(1, ListTempAtkP1); TempAtkP1.Add(2, ListTempAtkP1); TempAtkP1.Add(3, ListTempAtkP1); var TempWalkP2 = new Dictionary <int, List <string> >(); var List_TempWalkP2 = new List <string>(); TempWalkP2.Add(4, List_TempWalkP2); TempWalkP2.Add(5, List_TempWalkP2); TempWalkP2.Add(6, List_TempWalkP2); var TempDefP2 = new Dictionary <int, List <string> >(); var ListTempDefP2 = new List <string>(); TempDefP2.Add(4, ListTempDefP2); TempDefP2.Add(5, ListTempDefP2); TempDefP2.Add(6, ListTempDefP2); var TempAtkP2 = new Dictionary <int, List <string> >(); var ListTempAtkP2 = new List <string>(); TempAtkP2.Add(4, ListTempAtkP2); TempAtkP2.Add(5, ListTempAtkP2); TempAtkP2.Add(6, ListTempAtkP2); foreach (var _character in _ResponseP1) { if (_character.id == 1) { P1.MeeleCurrentTile = _character.CurrentTile; } if (_character.id == 2) { P1.ArcherCurrentTile = _character.CurrentTile; } if (_character.id == 3) { P1.MageCurrentTile = _character.CurrentTile; } foreach (var walked in _character.WalkedTiles) { List_TempWalkP1.Add(walked); TempWalkP1[_character.id] = List_TempWalkP1; } foreach (var def in _character.ActionTilesDef) { ListTempDefP1.Add(def); TempDefP1[_character.id] = ListTempDefP1; } foreach (var atk in _character.ActionTilesAtk) { ListTempAtkP1.Add(atk); TempAtkP1[_character.id] = ListTempAtkP1; } } foreach (var _character in _ResponseP2) { if (_character.id == 4) { P2.MeeleCurrentTile = _character.CurrentTile; } if (_character.id == 5) { P2.ArcherCurrentTile = _character.CurrentTile; } if (_character.id == 6) { P2.MageCurrentTile = _character.CurrentTile; } foreach (var walked in _character.WalkedTiles) { List_TempWalkP2.Add(walked); TempWalkP2[_character.id] = List_TempWalkP2; } foreach (var def in _character.ActionTilesDef) { ListTempDefP2.Add(def); TempDefP2[_character.id] = ListTempDefP2; } foreach (var atk in _character.ActionTilesAtk) { ListTempAtkP2.Add(atk); TempAtkP2[_character.id] = ListTempAtkP2; } } //15 action max for (int turno = 0; turno < 15; turno++) { var CHAR1W = TempWalkP1[1].Count >= turno + 1 ? TempWalkP1[1][turno] : string.Empty; var CHAR1A = TempAtkP1[1].Count >= turno + 1 ? TempAtkP1[1][turno] : string.Empty; var CHAR1D = TempDefP1[1].Count >= turno + 1 ? TempDefP1[1][turno] : string.Empty; var CHAR2W = TempWalkP1[2].Count >= turno + 1 ? TempWalkP1[2][turno] : string.Empty; var CHAR2A = TempAtkP1[2].Count >= turno + 1 ? TempAtkP1[2][turno] : string.Empty; var CHAR2D = TempDefP1[2].Count >= turno + 1 ? TempDefP1[2][turno] : string.Empty; var CHAR3W = TempWalkP1[3].Count >= turno + 1 ? TempWalkP1[3][turno] : string.Empty; var CHAR3A = TempAtkP1[3].Count >= turno + 1 ? TempAtkP1[3][turno] : string.Empty; var CHAR3D = TempDefP1[3].Count >= turno + 1 ? TempDefP1[3][turno] : string.Empty; var CHAR4W = TempWalkP2[4].Count >= turno + 1 ? TempWalkP2[4][turno] : string.Empty; var CHAR4A = TempAtkP2[4].Count >= turno + 1 ? TempAtkP2[4][turno] : string.Empty; var CHAR4D = TempDefP2[4].Count >= turno + 1 ? TempDefP2[4][turno] : string.Empty; var CHAR5W = TempWalkP2[5].Count >= turno + 1 ? TempWalkP2[5][turno] : string.Empty; var CHAR5A = TempAtkP2[5].Count >= turno + 1 ? TempAtkP2[5][turno] : string.Empty; var CHAR5D = TempDefP2[5].Count >= turno + 1 ? TempDefP2[5][turno] : string.Empty; var CHAR6W = TempWalkP2[6].Count >= turno + 1 ? TempWalkP2[6][turno] : string.Empty; var CHAR6A = TempAtkP2[6].Count >= turno + 1 ? TempAtkP2[6][turno] : string.Empty; var CHAR6D = TempDefP2[6].Count >= turno + 1 ? TempDefP2[6][turno] : string.Empty; //Team 1 if (CHAR1W == CHAR4A || CHAR1W == CHAR5A || CHAR1W == CHAR6A) { //dano if (CHAR1W == CHAR4A) { P1.MeeleCurrentHP -= P2.MeeleAtk; } if (CHAR1W == CHAR5A) { P1.MeeleCurrentHP -= P2.ArcherAtk; } if (CHAR1W == CHAR6A) { P1.MeeleCurrentHP -= P2.MageAtk; } } if (CHAR2W == CHAR4A || CHAR2W == CHAR5A || CHAR2W == CHAR6A) { //dano if (CHAR2W == CHAR4A) { P1.ArcherCurrentHP -= P2.MeeleAtk; } if (CHAR2W == CHAR5A) { P1.ArcherCurrentHP -= P2.ArcherAtk; } if (CHAR2W == CHAR6A) { P1.ArcherCurrentHP -= P2.MageAtk; } } if (CHAR3W == CHAR4A || CHAR3W == CHAR5A || CHAR3W == CHAR6A) { //dano if (CHAR3W == CHAR4A) { P1.MageCurrentHP -= P2.MeeleAtk; } if (CHAR3W == CHAR5A) { P1.MageCurrentHP -= P2.ArcherAtk; } if (CHAR3W == CHAR6A) { P1.MageCurrentHP -= P2.MageAtk; } } if (CHAR1A == CHAR4D || CHAR1A == CHAR5D || CHAR1A == CHAR6D) { //def if (CHAR1A == CHAR4D) { P2.MeeleCurrentHP -= P1.MeeleAtk - P2.MeeleDef; } if (CHAR1A == CHAR5A) { P2.ArcherCurrentHP -= P1.MeeleAtk - P2.ArcherDef; } if (CHAR1A == CHAR6A) { P2.MageCurrentHP -= P1.MeeleAtk - P2.MageDef; } } if (CHAR2A == CHAR4D || CHAR2A == CHAR5D || CHAR2A == CHAR6D) { //def if (CHAR2A == CHAR4D) { P2.MeeleCurrentHP -= P1.ArcherAtk - P2.MeeleDef; } if (CHAR2A == CHAR5A) { P2.ArcherCurrentHP -= P1.ArcherAtk - P2.ArcherDef; } if (CHAR2A == CHAR6A) { P2.MageCurrentHP -= P1.ArcherAtk - P2.MageDef; } } if (CHAR3A == CHAR4D || CHAR3A == CHAR5D || CHAR3A == CHAR6D) { //def if (CHAR3A == CHAR4D) { P2.MeeleCurrentHP -= P1.MageAtk - P2.MeeleDef; } if (CHAR3A == CHAR5A) { P2.ArcherCurrentHP -= P1.MageAtk - P2.ArcherDef; } if (CHAR3A == CHAR6A) { P2.MageCurrentHP -= P1.MageAtk - P2.MageDef; } } if (CHAR1A == CHAR4A || CHAR1A == CHAR5A || CHAR1A == CHAR6A) { //atk atk if (CHAR1A == CHAR4A) { P1.MeeleCurrentHP -= P1.MeeleAtk - P2.MeeleAtk; P2.MeeleCurrentHP -= P1.MeeleAtk - P2.MeeleAtk; } if (CHAR1A == CHAR5A) { P1.MeeleCurrentHP -= P1.MeeleAtk - P2.ArcherAtk; P2.ArcherCurrentHP -= P1.MeeleAtk - P2.ArcherAtk; } if (CHAR1A == CHAR6A) { P1.MeeleCurrentHP -= P1.MeeleAtk - P2.MageAtk; P2.MageCurrentHP -= P1.MeeleAtk - P2.MageAtk; } } if (CHAR2A == CHAR4A || CHAR2A == CHAR5A || CHAR2A == CHAR6A) { //atk atk if (CHAR2A == CHAR4A) { P1.ArcherCurrentHP -= P1.ArcherAtk - P2.MeeleAtk; P2.MeeleCurrentHP -= P1.ArcherAtk - P2.MeeleAtk; } if (CHAR2A == CHAR5A) { P1.ArcherCurrentHP -= P1.ArcherAtk - P2.ArcherAtk; P2.ArcherCurrentHP -= P1.ArcherAtk - P2.ArcherAtk; } if (CHAR2A == CHAR6A) { P1.ArcherCurrentHP -= P1.ArcherAtk - P2.MageAtk; P2.MageCurrentHP -= P1.ArcherAtk - P2.MageAtk; } } if (CHAR3A == CHAR4A || CHAR3A == CHAR5A || CHAR3A == CHAR6A) { //atk atk if (CHAR3A == CHAR4A) { P1.MageCurrentHP -= P1.MageAtk - P2.MeeleAtk; P2.MeeleCurrentHP -= P1.MageAtk - P2.MeeleAtk; } if (CHAR3A == CHAR5A) { P1.MageCurrentHP -= P1.MageAtk - P2.ArcherAtk; P2.ArcherCurrentHP -= P1.MageAtk - P2.ArcherAtk; } if (CHAR3A == CHAR6A) { P1.MageCurrentHP -= P1.MageAtk - P2.MageAtk; P2.MageCurrentHP -= P1.MageAtk - P2.MageAtk; } } /////////////////////////////////////////////////////////////////////////////////////////////////////////// //Team 2 if (CHAR4W == CHAR1A || CHAR4W == CHAR2A || CHAR4W == CHAR3A) { //dano if (CHAR4W == CHAR1A) { P2.MeeleCurrentHP -= P1.MeeleAtk; } if (CHAR4W == CHAR2A) { P2.MeeleCurrentHP -= P1.ArcherAtk; } if (CHAR4W == CHAR3A) { P2.MeeleCurrentHP -= P1.MageAtk; } } if (CHAR5W == CHAR1A || CHAR5W == CHAR2A || CHAR5W == CHAR3A) { //dano if (CHAR5W == CHAR1A) { P2.ArcherCurrentHP -= P1.MeeleAtk; } if (CHAR5W == CHAR2A) { P2.ArcherCurrentHP -= P1.ArcherAtk; } if (CHAR5W == CHAR3A) { P2.ArcherCurrentHP -= P1.MageAtk; } } if (CHAR6W == CHAR1A || CHAR6W == CHAR2A || CHAR6W == CHAR3A) { //dano if (CHAR6W == CHAR1A) { P2.MageCurrentHP -= P1.MeeleAtk; } if (CHAR6W == CHAR2A) { P2.MageCurrentHP -= P1.ArcherAtk; } if (CHAR6W == CHAR3A) { P2.MageCurrentHP -= P1.MageAtk; } } if (CHAR4A == CHAR1D || CHAR4A == CHAR2D || CHAR4A == CHAR3D) { //def if (CHAR4A == CHAR1D) { P1.MeeleCurrentHP -= P2.MeeleAtk - P1.MeeleDef; } if (CHAR4A == CHAR2D) { P1.ArcherCurrentHP -= P2.MeeleAtk - P1.ArcherDef; } if (CHAR4A == CHAR3D) { P1.MageCurrentHP -= P2.MeeleAtk - P1.MageDef; } } if (CHAR5A == CHAR1D || CHAR5A == CHAR2D || CHAR5A == CHAR3D) { //def if (CHAR5A == CHAR1D) { P1.MeeleCurrentHP -= P2.ArcherAtk - P1.MeeleDef; } if (CHAR5A == CHAR2D) { P1.ArcherCurrentHP -= P2.ArcherAtk - P1.ArcherDef; } if (CHAR5A == CHAR3D) { P1.MageCurrentHP -= P2.ArcherAtk - P1.MageDef; } } if (CHAR6A == CHAR1D || CHAR6A == CHAR2D || CHAR6A == CHAR3D) { //def if (CHAR6A == CHAR1D) { P1.MeeleCurrentHP -= P2.MageAtk - P1.MeeleDef; } if (CHAR6A == CHAR2D) { P1.ArcherCurrentHP -= P2.MageAtk - P1.ArcherDef; } if (CHAR6A == CHAR3D) { P1.MageCurrentHP -= P2.MageAtk - P1.MageDef; } } } JSONClass rootNode = new JSONClass(); rootNode.Add("id", new JSONData(1)); rootNode.Add("CurrentHP", new JSONData(P1.MeeleCurrentHP)); rootNode.Add("CurrentAP", new JSONData(P1.MeeleCurrentAP)); rootNode.Add("CurrentTile", new JSONData(P1.MeeleCurrentTile)); ListToSend.Add(rootNode); rootNode = new JSONClass(); rootNode.Add("id", new JSONData(2)); rootNode.Add("CurrentHP", new JSONData(P1.ArcherCurrentHP)); rootNode.Add("CurrentAP", new JSONData(P1.ArcherCurrentAP)); rootNode.Add("CurrentTile", new JSONData(P1.ArcherCurrentTile)); ListToSend.Add(rootNode); rootNode = new JSONClass(); rootNode.Add("id", new JSONData(3)); rootNode.Add("CurrentHP", new JSONData(P1.MageCurrentHP)); rootNode.Add("CurrentAP", new JSONData(P1.MageCurrentAP)); rootNode.Add("CurrentTile", new JSONData(P1.MageCurrentTile)); ListToSend.Add(rootNode); rootNode = new JSONClass(); rootNode.Add("id", new JSONData(4)); rootNode.Add("CurrentHP", new JSONData(P2.MeeleCurrentHP)); rootNode.Add("CurrentAP", new JSONData(P2.MeeleCurrentAP)); rootNode.Add("CurrentTile", new JSONData(P2.MeeleCurrentTile)); ListToSend.Add(rootNode); rootNode = new JSONClass(); rootNode.Add("id", new JSONData(5)); rootNode.Add("CurrentHP", new JSONData(P2.ArcherCurrentHP)); rootNode.Add("CurrentAP", new JSONData(P2.ArcherCurrentAP)); rootNode.Add("CurrentTile", new JSONData(P2.ArcherCurrentTile)); ListToSend.Add(rootNode); rootNode = new JSONClass(); rootNode.Add("id", new JSONData(6)); rootNode.Add("CurrentHP", new JSONData(P2.MageCurrentHP)); rootNode.Add("CurrentAP", new JSONData(P2.MageCurrentAP)); rootNode.Add("CurrentTile", new JSONData(P2.MageCurrentTile)); ListToSend.Add(rootNode); CURRENT_STATE = GameState.ON; if ((Action)p_callbackResponseTurn != null) { ((Action)p_callbackResponseTurn)(); } } }
//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; } }
/* * { "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); } }
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; }
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)); root.Add ("channels", channels); _OnQueryChannelList(root.ToString()); } }
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); } } }
public override JSONNode this [int aIndex] { get { return new JSONLazyCreator (this); } set { var tmp = new JSONArray (); tmp.Add (value); Set (tmp); } }
void SendActions() { SimpleJSON.JSONArray ListToSend = new SimpleJSON.JSONArray(); Transform[] p_group; if (GlobalVariables.Player_Team_Chosen == "A") { p_group = GameObject.Find("BLUE_SNAKES_Controller").GetComponentsInChildren <Transform>(); } else { p_group = GameObject.Find("RED_SNAKES_Controller").GetComponentsInChildren <Transform>(); } foreach (Transform child in p_group) { for (int i = 0; i < child.childCount; i++) { var character = child.GetChild(i); if (character.tag == "Player") { CharactersModel _Character_Actions = new CharactersModel(); Player PlayerScript = character.GetComponent <Player>(); if (character.name == "Barbaro" || character.name == "Guerreiro") { foreach (var walk in GlobalVariables.WalkedMeele) { _Character_Actions.WalkedTiles.Add(walk.name); } foreach (var atk in GlobalVariables.ActionMeeleAtk) { _Character_Actions.ActionTilesAtk.Add(atk.name); } foreach (var def in GlobalVariables.ActionMeeleDef) { _Character_Actions.ActionTilesDef.Add(def.name); } } else if (character.name == "Ranger" || character.name == "Arqueiro") { foreach (var walk in GlobalVariables.WalkedRange) { _Character_Actions.WalkedTiles.Add(walk.name); } foreach (var atk in GlobalVariables.ActionRangeAtk) { _Character_Actions.ActionTilesAtk.Add(atk.name); } foreach (var def in GlobalVariables.ActionRangeDef) { _Character_Actions.ActionTilesDef.Add(def.name); } } else { foreach (var walk in GlobalVariables.WalkedMage) { _Character_Actions.WalkedTiles.Add(walk.name); } foreach (var atk in GlobalVariables.ActionMageAtk) { _Character_Actions.ActionTilesAtk.Add(atk.name); } foreach (var def in GlobalVariables.ActionMageDef) { _Character_Actions.ActionTilesDef.Add(def.name); } } _Character_Actions.CurrentAP = PlayerScript.ActionPoints; _Character_Actions.CurrentHP = PlayerScript.HP; _Character_Actions.CurrentTile = PlayerScript.CurrentTile; _Character_Actions.id = PlayerScript.id; ListToSend.Add(JsonUtility.ToJson(_Character_Actions)); } } } GlobalVariables.__socket.SendData(ListToSend.ToString()); GlobalVariables.__socket.StartReadSocketDataThread(); }
/* *{ "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; }
private static JSONNode LevelToJSON(Level level) { JSONClass root = new JSONClass (); JSONData name = new JSONData (level.Name); root.Add ("name",name); JSONData music = new JSONData (level.MusicPath); root.Add ("music",name); JSONData map = new JSONData (level.Map); root.Add ("map",name); JSONData tutorial = new JSONData (level.Tutorial); root.Add ("tutorial", tutorial); int i = 0; JSONArray items = new JSONArray (); foreach (Item itemInList in level.ItemList) { JSONClass item = new JSONClass(); i++; JSONData id = new JSONData (i); item.Add ("id", id); JSONData type = new JSONData (itemInList.Type); item.Add ("type", type); JSONData position_seconds = new JSONData (itemInList.PositionInSeconds); item.Add ("position_seconds", position_seconds); JSONData position_x = new JSONData (itemInList.PositionInX); item.Add ("position_x", position_x); items.Add (item); } root.Add ("items", items); return root; }
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); }
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; }
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; }
public static JSONNode Deserialize(BinaryReader aReader) { var type = (JSONBinaryTag)aReader.ReadByte(); switch (type) { case JSONBinaryTag.Array: { var count = aReader.ReadInt32(); var tmp = new JSONArray(); for (var i = 0; i < count; i++) { tmp.Add(Deserialize(aReader)); } return(tmp); } case JSONBinaryTag.Class: { var count = aReader.ReadInt32(); var tmp = new JSONClass(); for (var i = 0; i < count; i++) { var 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())); } case JSONBinaryTag.LongValue: { return(new JSONData(aReader.ReadInt64())); } case JSONBinaryTag.Null: { return(new JSONData(null)); } } throw new Exception("JSON Deserialize: Unknown tag in stream"); }
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)"); } } } } }
public override void Add(JSONNode aItem) { var tmp = new JSONArray(); tmp.Add(aItem); Set(tmp); }
public override void Add (JSONNode aItem) { var tmp = new JSONArray (); tmp.Add (aItem); Set (tmp); }
public static JSONArray SerializeComponents(GameObject obj) { JSONArray a = new JSONArray(); IJSONSerializable[] serializables = obj.GetInterfaces<IJSONSerializable>().ToArray(); foreach (IJSONSerializable hs in serializables) { JSONClass hsNode = new JSONClass(); hs.OnSerialize(hsNode); hsNode["_meta_cls"] = hs.GetType().Name; a.Add(hsNode); } return a; }
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); } } }
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 (); }