public HTTPResponse.Builder ToHTTPResponseBuilder() { if (!Timestamp.HasValue) { Timestamp = DateTime.UtcNow; } HTTPResponseBuilder.Server = Request.HTTPRequest.HTTPServer.DefaultServerName; HTTPResponseBuilder.Date = Timestamp.Value; HTTPResponseBuilder.AccessControlAllowOrigin = "*"; HTTPResponseBuilder.Connection = "close"; if (Request.HTTPRequest.HTTPMethod != HTTPMethod.OPTIONS) { HTTPResponseBuilder.ContentType = HTTPContentType.JSON_UTF8; if (HTTPResponseBuilder.Content == null) { HTTPResponseBuilder.Content = JSONObject.Create( Data != null ? new JProperty("data", Data) : null, new JProperty("status_code", StatusCode ?? 2000), StatusMessage.IsNotNullOrEmpty() ? new JProperty("status_message", StatusMessage) : null, AdditionalInformation.IsNotNullOrEmpty() ? new JProperty("additionalInformation", AdditionalInformation) : null, RequestId.HasValue ? new JProperty("requestId", RequestId.Value.ToString()) : null, CorrelationId.HasValue ? new JProperty("correlationId", CorrelationId.Value.ToString()) : null, new JProperty("timestamp", (Timestamp ?? DateTime.UtcNow).ToIso8601()) ).ToUTF8Bytes(); } } HTTPResponseBuilder.Set("X-Request-ID", Request.RequestId). Set("X-Correlation-ID", Request.CorrelationId); HTTPResponseBuilder.SubprotocolResponse = this; return(HTTPResponseBuilder); }
private static UserProfile UserProfileFromFBJson(JSONObject fbJsonObject, FacebookProvider provider) { JSONObject soomlaJsonObject = new JSONObject(); soomlaJsonObject.AddField(PJSONConsts.UP_PROVIDER, Provider.FACEBOOK.ToString()); soomlaJsonObject.AddField(PJSONConsts.UP_PROFILEID, fbJsonObject["id"].str); string name = fbJsonObject ["name"].str; soomlaJsonObject.AddField(PJSONConsts.UP_USERNAME, name); string email = fbJsonObject ["email"] != null ? fbJsonObject ["email"].str : null; if (email == null) { email = Regex.Replace(name, @"\s+", ".") + "@facebook.com"; } soomlaJsonObject.AddField(PJSONConsts.UP_EMAIL, email); soomlaJsonObject.AddField(PJSONConsts.UP_FIRSTNAME, fbJsonObject["first_name"].str); soomlaJsonObject.AddField(PJSONConsts.UP_LASTNAME, fbJsonObject["last_name"].str); soomlaJsonObject.AddField(PJSONConsts.UP_AVATAR, fbJsonObject["picture"]["data"]["url"].str); if (fbJsonObject["gender"] != null) { soomlaJsonObject.AddField(PJSONConsts.UP_GENDER, fbJsonObject["gender"].str); } if (fbJsonObject["languages"] != null && fbJsonObject["languages"].Count > 0 && fbJsonObject["languages"][0] != null && fbJsonObject["languages"][0]["name"] != null) { soomlaJsonObject.AddField(PJSONConsts.UP_LANGUAGE, fbJsonObject["languages"][0]["name"].str); } if (fbJsonObject["location"] != null && fbJsonObject["location"]["name"] != null) { soomlaJsonObject.AddField(PJSONConsts.UP_LOCATION, fbJsonObject["location"]["name"].str); } if (fbJsonObject["birthday"] != null) { soomlaJsonObject.AddField(PJSONConsts.UP_BIRTHDAY, fbJsonObject["birthday"].str); } if (provider != null) //let us to know if method called during own profile receiving { Dictionary <String, JSONObject> extraDict = new Dictionary <String, JSONObject>(); extraDict.Add("access_token", JSONObject.StringObject(AccessToken.CurrentAccessToken.TokenString)); JSONObject permissionsObject = JSONObject.Create(JSONObject.Type.ARRAY); foreach (String permission in provider.permissions) { permissionsObject.Add(permission); } extraDict.Add("permissions", permissionsObject); extraDict.Add("expiration_date", new JSONObject((AccessToken.CurrentAccessToken.ExpirationTime - new DateTime(1970, 1, 1)).TotalSeconds)); soomlaJsonObject.AddField(PJSONConsts.UP_EXTRA, new JSONObject(extraDict)); } UserProfile userProfile = new UserProfile(soomlaJsonObject); return(userProfile); }
public Boolean ParseMandatory <TEnum>(String PropertyName, String PropertyDescription, String DefaultServerName, out TEnum Value, HTTPRequest HTTPRequest, out HTTPResponse HTTPResponse) where TEnum : struct { Object JSONToken = null; if (!TryGetValue(PropertyName, out JSONToken)) { HTTPResponse = new HTTPResponseBuilder(HTTPRequest) { HTTPStatusCode = HTTPStatusCode.BadRequest, Server = DefaultServerName, Date = DateTime.Now, ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create( new JProperty("description", "Missing JSON property '" + PropertyName + "'!") ).ToUTF8Bytes() }; Value = default(TEnum); return(false); } if (JSONToken != null) { if (!Enum.TryParse <TEnum>(JSONToken.ToString(), true, out Value)) { HTTPResponse = new HTTPResponseBuilder(HTTPRequest) { HTTPStatusCode = HTTPStatusCode.BadRequest, Server = DefaultServerName, Date = DateTime.Now, ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create( new JProperty("description", "Unknown " + PropertyDescription + "!") ).ToUTF8Bytes() }; Value = default(TEnum); return(false); } } Value = default(TEnum); HTTPResponse = null; return(true); }
public void Update() { if (Input.GetKeyDown(KeyCode.C)) { Debug.Log("Connecting ..."); ddpConnection.Connect(); } if (Input.GetKeyDown(KeyCode.V)) { Debug.Log("Closing connection ..."); ddpConnection.Close(); } if (Input.GetKeyDown(KeyCode.S)) { friendSub = ddpConnection.Subscribe("friends"); friendSub.OnReady = (Subscription obj) => { Debug.Log("Ready subscription: " + obj.id); }; } if (Input.GetKeyDown(KeyCode.U)) { ddpConnection.Unsubscribe(friendSub); } if (Input.GetKeyDown(KeyCode.R)) { ddpConnection.Call("friends.removeAll"); } if (Input.GetKeyDown(KeyCode.F)) { MethodCall methodCall = ddpConnection.Call("friends.create", JSONObject.CreateStringObject("Coco")); methodCall.OnUpdated = (MethodCall obj) => { Debug.Log("Updated, methodId=" + obj.id); }; methodCall.OnResult = (MethodCall obj) => { Debug.Log("Result = " + obj.result); }; } if (Input.GetKeyDown(KeyCode.A)) { MethodCall methodCall = ddpConnection.Call("friends.add", JSONObject.Create(7), JSONObject.Create(5)); methodCall.OnUpdated = (MethodCall obj) => { Debug.Log("Updated, methodId=" + obj.id); }; methodCall.OnResult = (MethodCall obj) => { Debug.Log("Result = " + obj.result); }; } }
protected void CheckRawCopy(ref JSONObject rawJSON) { if (rawJSON != null) { rawJSON.Clear(); } else { rawJSON = JSONObject.Create(JSONObject.Type.OBJECT); } }
void CheckEndGame() { #if HAS_WEBSERVICE _webService.GetJsonRaw(AccessTypes.HasEnded, _cities.GetSelectedCity().id, (WebObject response) => { Debug.Log("Checking if game has finished."); EndGame(new SocketIOEvent("EndGame", JSONObject.Create(response.rawJson))); }); #endif }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomDisplayTextSerializer">A delegate to serialize custom multi-language text JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <DisplayText> CustomDisplayTextSerializer = null) { var JSON = JSONObject.Create( new JProperty("language", Language.ToString()), new JProperty("text", Text) ); return(CustomDisplayTextSerializer != null ? CustomDisplayTextSerializer(this, JSON) : JSON); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomChangeConfigurationRequestSerializer">A delegate to serialize custom change configuration requests.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <ChangeConfigurationRequest> CustomChangeConfigurationRequestSerializer = null) { var JSON = JSONObject.Create( new JProperty("key", Key), new JProperty("value", Value) ); return(CustomChangeConfigurationRequestSerializer != null ? CustomChangeConfigurationRequestSerializer(this, JSON) : JSON); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomFirstResponseSerializer">A delegate to serialize custom first response JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <FirstResponse> CustomFirstResponseSerializer = null) { var JSON = JSONObject.Create( new JProperty("responseTime", Math.Round(ResponseTime.TotalSeconds, 0)), new JProperty("changeSetId", ChangeSetId.ToString()) ); return(CustomFirstResponseSerializer != null ? CustomFirstResponseSerializer(this, JSON) : JSON); }
public void GetQuestionsTest_Get_Difficulty() { string data = Resources.Load <TextAsset>("data").text; //use dummy data JSONObject json = JSONObject.Create(data); //get the difficulty int difficulty = (int)json["game"]["difficulty"].f; Assert.AreEqual(difficulty, 1); }
public void GetQuestionsTest_Get_HighScore() { string data = Resources.Load <TextAsset>("data").text; //use dummy data JSONObject json = JSONObject.Create(data); //get the highscore int highScore = (int)json["game"]["highscore"].f; Assert.AreEqual(highScore, 166); }
// 错误使用 观察Debug private void Test_Example7() { JSONObject json = JSONObject.Create("[1,2,3]"); json.Add(4); json.Add(5); json.Add(6); json.SetField("tK1", 7); json.SetField("tK2", 8); Debug.Log(json.ToString()); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="Embedded">Whether this data is embedded into another data structure.</param> /// <param name="IncludeCryptoHash">Include the crypto hash value of this object.</param> public override JObject ToJSON(Boolean Embedded = false, Boolean IncludeCryptoHash = false) => JSONObject.Create( new JProperty("@id", Id.ToString()), new JProperty("sender", Sender.ToString()), new JProperty("subject", Subject.ToJSON()), new JProperty("text", Text.ToJSON()) );
public void testCreatureDeserialization() { LibraryLoader.loadMoveLibrary(); string creatureJSONString = "{\"creatureId\":1,\n\"creatureName\":\"\",\n\"baseStats\":[10,10,10,10],\n\"abilityId\":1,\n\"moves\":[\"Strike\",\"Slam\"],\n\"focalPoints\":[\n{\n\"description\":\"Small boost to strength\",\n\"statMods\":{\n\"STR\":[5,1]\n}\n},\n{\n\"description\":\"Small boost to armor\",\n\"statMods\":{\n\"ARM\":[5, 1]\n}\n},\n{\n\"description\":\"Additional armor scaling\",\n\"statMods\":{\n\"ARM\":[0, 1.1]\n}\n},\n{\n\"description\":\"Small boost to speed\",\n\"statMods\":{\n\"SPD\":[5, 1]\n}\n}\n],\n\"baseForm\":{\n\"creatureTypes\":[\"Vital\"],\n\"abilityId\":1,\n\"revealAction\":null\n},\n\"availableForms\":[\n{\n\"creatureTypes\":[\"Flame\"],\n\"statMods\":{\n\"STR\":[5, 1],\n\"ARM\":[0, 1],\n\"SPD\":[0, 1]\n},\n\"moveId\":null,\n\"abilityId\":1,\n\"revealAction\":null\n}\n]\n}"; JSONObject creatureJSON = JSONObject.Create(creatureJSONString); Creature actual = Creature.fromJSONObject(creatureJSON); HashSet <Move> expectedMoves = new HashSet <Move>(); expectedMoves.Add(MoveLibrary.get("Strike")); expectedMoves.Add(MoveLibrary.get("Slam")); StatModifier sm1 = new StatModifier(5, 1); StatModifier sm2 = new StatModifier(0, 1.1); StatModifier sm3 = new StatModifier(0, 1); FocusPoint fp1 = new FocusPoint(null, null, makeListOfStatMod(StatName.STR, sm1), "Small boost to strength"); FocusPoint fp2 = new FocusPoint(null, null, makeListOfStatMod(StatName.ARM, sm1), "Small boost to armor"); FocusPoint fp3 = new FocusPoint(null, null, makeListOfStatMod(StatName.ARM, sm2), "Additional armor scaling"); FocusPoint fp4 = new FocusPoint(null, null, makeListOfStatMod(StatName.SPD, sm1), "Small boost to speed"); FocalPoints expectedFocalPoints = new FocalPoints(fp1, fp2, fp3, fp4); CreatureStats expectedBaseStats = new CreatureStats(10, 10, 10, 10); Ability expectedAbility = null; HashSet <CreatureType> expectedTypesBase = new HashSet <CreatureType>(); expectedTypesBase.Add(CreatureType.VITAL); CreatureForm expectedBaseForm = new CreatureForm(expectedTypesBase, null, null); HashSet <CreatureType> expectedTypesForm = new HashSet <CreatureType>(); expectedTypesForm.Add(CreatureType.FLAME); List <Pair <StatName, StatModifier> > expectedFormMods = new List <Pair <StatName, StatModifier> >(); expectedFormMods.Add(new Pair <StatName, StatModifier>(StatName.STR, sm1)); expectedFormMods.Add(new Pair <StatName, StatModifier>(StatName.ARM, sm3)); expectedFormMods.Add(new Pair <StatName, StatModifier>(StatName.SPD, sm3)); CreatureForm expectedAltForm = new CreatureForm(expectedTypesForm, expectedFormMods, null, null, null); //"availableForms\":[\n{\n\"creatureTypes\":[\"Flame\"],\n\"statMods\":{\n\"STR\":[5, 1],\n\"ARM\":[0, 1],\n\"SPD\":[0, 1]\n},\n\"moveId\":null,\n\"abilityId\":1,\n\"revealAction\":null\n}\n] List <CreatureForm> expectedAvailableForms = new List <CreatureForm>(); expectedAvailableForms.Add(expectedAltForm); foreach (Pair <StatName, StatModifier> pair in expectedAltForm.statMods) { Debug.Log("Alt form mod: " + pair.ToString()); } Creature expected = new Creature(1, "", expectedMoves, expectedFocalPoints, expectedAbility, expectedBaseStats, expectedBaseForm, expectedAvailableForms); Assert.That(expected.Equals(actual)); }
public void CmdRegisterEntity(GameObject prefab, Vector3 position, Vector3 rotation) { Entity entity = new Entity(); entity.type = prefab.GetComponent <NetworkIdentity>().GetEntityType(); entity.position = new Vector3Json(position); entity.rotation = new Vector3Json(rotation); entity.prefabName = prefab.name; NetworkManager.instance.GetSocket().Emit("Packet::RegisterEntity", JSONObject.Create(JsonUtility.ToJson(entity))); }
public Boolean ParseMandatory(String PropertyName, String PropertyDescription, String DefaultServerName, out JToken JSON, HTTPRequest HTTPRequest, out HTTPResponse HTTPResponse) { Object JSONToken = null; if (PropertyName.IsNotNullOrEmpty()) { if (!TryGetValue(PropertyName, out JSONToken)) { HTTPResponse = new HTTPResponseBuilder(HTTPRequest) { HTTPStatusCode = HTTPStatusCode.BadRequest, Server = DefaultServerName, Date = DateTime.Now, ContentType = HTTPContentType.JSON_UTF8, Content = JSONObject.Create( new JProperty("description", "Missing JSON property '" + PropertyName + "'!") ).ToUTF8Bytes() }; JSON = new JValue(false); return(false); } } JSON = null; switch (JSONToken.GetType().Name) { case "String": JSON = new JValue(JSONToken); break; case "JObject": JSON = JObject.Parse(JSONToken.ToString()); break; case "JArray": JSON = JArray.Parse(JSONToken.ToString()); break; } // JSON = JToken.Parse(JSONToken.ToString()); HTTPResponse = null; return(true); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomEnergySourceSerializer">A delegate to serialize custom energy source JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <EnergySource> CustomEnergySourceSerializer = null) { var JSON = JSONObject.Create( new JProperty("source", Source.ToString()), new JProperty("percentage", Percentage) ); return(CustomEnergySourceSerializer != null ? CustomEnergySourceSerializer(this, JSON) : JSON); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomVersionDetailSerializer">A delegate to serialize custom version detail JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <VersionDetail> CustomVersionDetailSerializer = null) { var JSON = JSONObject.Create( new JProperty("version", VersionId.ToString()), new JProperty("endpoints", new JArray(Endpoints.SafeSelect(endpoint => endpoint.ToJSON()))) ); return(CustomVersionDetailSerializer != null ? CustomVersionDetailSerializer(this, JSON) : JSON); }
private IEnumerator PrivateRoomSmsRequest(int selectedIndex) { yield return(new WaitForSeconds(1)); Dictionary <string, string> json = new Dictionary <string, string>(); json.Add("login", PlayerManager.Instance.loginData.user); json.Add("room", channels[selectedIndex]); socket.Emit("room", JSONObject.Create(json)); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomExceptionalPeriodSerializer">A delegate to serialize custom regular hours JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <ExceptionalPeriod> CustomExceptionalPeriodSerializer = null) { var JSON = JSONObject.Create( new JProperty("period_begin", Begin.ToIso8601()), new JProperty("period_end", End.ToIso8601()) ); return(CustomExceptionalPeriodSerializer != null ? CustomExceptionalPeriodSerializer(this, JSON) : JSON); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomPeriodSerializer">A delegate to serialize custom time period JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <Period> CustomPeriodSerializer = null) { var JSON = JSONObject.Create( new JProperty("begin", Begin.ToString()), new JProperty("end", End.ToString()) ); return(CustomPeriodSerializer != null ? CustomPeriodSerializer(this, JSON) : JSON); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomHashedPINSerializer">A delegate to serialize custom hashed PIN JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <HashedPIN> CustomHashedPINSerializer = null) { var JSON = JSONObject.Create( new JProperty("Function", Function.ToString()), new JProperty("Value", Value.ToString()) ); return(CustomHashedPINSerializer != null ? CustomHashedPINSerializer(this, JSON) : JSON); }
public void Login(string username, string password) { JSONObject userObj = JSONObject.Create(); userObj.AddField("username", username); JSONObject loginPasswordObj = JSONObject.Create(); loginPasswordObj.AddField("user", userObj); loginPasswordObj.AddField("password", GetPasswordObj(password)); MethodCall loginCall = connection.Call("login", loginPasswordObj); loginCall.OnResult += HandleLoginResult; }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomChangeAvailabilityRequestSerializer">A delegate to serialize custom ChangeAvailability requests.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <ChangeAvailabilityRequest> CustomChangeAvailabilityRequestSerializer) { var JSON = JSONObject.Create( new JProperty("connectorId", ConnectorId.Value), new JProperty("type", Availability.AsText()) ); return(CustomChangeAvailabilityRequestSerializer != null ? CustomChangeAvailabilityRequestSerializer(this, JSON) : JSON); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomVersionSerializer">A delegate to serialize custom version information JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <VersionInformation> CustomVersionSerializer = null) { var JSON = JSONObject.Create( new JProperty("version", Id.ToString()), new JProperty("url", URL.ToString()) ); return(CustomVersionSerializer != null ? CustomVersionSerializer(this, JSON) : JSON); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomEnvironmentalImpactSerializer">A delegate to serialize custom environmental impact JSON objects.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <EnvironmentalImpact> CustomEnvironmentalImpactSerializer = null) { var JSON = JSONObject.Create( new JProperty("category", Category.ToString()), new JProperty("amount", Amount) ); return(CustomEnvironmentalImpactSerializer != null ? CustomEnvironmentalImpactSerializer(this, JSON) : JSON); }
IEnumerator Coroutine(WWW req, Action <GameState> callback) { yield return(req); Debug.Log(req.error); JSONObject state = JSONObject.Create(req.text); callback(new GameState(state)); _busy = false; }
public void LoginAndGetInfo(Action <JSONObject> callback, Action <string> errorCallback) { JSONObject jSONObject = JSONObject.Create(); jSONObject.AddField("OS", SystemInfo.operatingSystem); jSONObject.AddField("AndroidDeviceId", GetSystemUniqueIdentifier()); jSONObject.AddField("AndroidDevice", SystemInfo.deviceModel); string loginEndpoint = "LoginWithAndroidDeviceID"; LoginAndGetInfo(jSONObject, loginEndpoint, callback, errorCallback); }
/// <summary> /// Return a JSON representation of this object. /// </summary> /// <param name="CustomAuthorizeResponseSerializer">A delegate to serialize custom authorize responses.</param> /// <param name="CustomIdTagInfoResponseSerializer">A delegate to serialize custom IdTagInfos.</param> public JObject ToJSON(CustomJObjectSerializerDelegate <AuthorizeResponse> CustomAuthorizeResponseSerializer = null, CustomJObjectSerializerDelegate <IdTagInfo> CustomIdTagInfoResponseSerializer = null) { var JSON = JSONObject.Create( new JProperty("idTagInfo", IdTagInfo.ToJSON(CustomIdTagInfoResponseSerializer)) ); return(CustomAuthorizeResponseSerializer != null ? CustomAuthorizeResponseSerializer(this, JSON) : JSON); }
public void UpdateUserDisplayName(string name, Action <JSONObject> callback, Action <string> errorCallback) { name = name.PadRight(3, ' '); name = name.Substring(0, Mathf.Min(name.Length, 25)); JSONObject jSONObject = JSONObject.Create(); jSONObject.AddField("DisplayName", name); PlayFabCommand cmd = new PlayFabCommand(PersistentSingleton <GameSettings> .Instance.PlayFabUrl + "UpdateUserTitleDisplayName", jSONObject, callback, errorCallback); QueueCommand(cmd); }