public static SignalRMessage[] FromJSON(JSONClass json) { List <SignalRMessage> result = new List <SignalRMessage>(); if (json.ContainsKey("M") && json["M"].AsArray != null) { foreach (JSONNode node in json["M"].AsArray) { SignalRMessage msg = new SignalRMessage(); msg.H = node.AsObject.ContainsKey("H") ? node.AsObject["H"].Value : string.Empty; msg.M = node.AsObject.ContainsKey("M") ? node.AsObject["M"].Value : string.Empty; if (node.AsObject.ContainsKey("A") && node.AsObject["A"].AsArray != null) { List <string> paramsA = new List <string>(); foreach (JSONNode nodeParam in node.AsObject["A"].AsArray) { paramsA.Add(nodeParam.Value); } msg.A = paramsA.ToArray(); } result.Add(msg); } } return(result.ToArray()); }
public void TryConnect() { onConnectionUpdate(ConnectionStatus.CONNECTING); try { var webRequest = (HttpWebRequest)WebRequest.Create(_socketUrl + string.Format("/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22{0}%22%7D%5D&_=1498643185939", _hubName)); var response = (HttpWebResponse)webRequest.GetResponse(); using (var sr = new StreamReader(response.GetResponseStream())) { var payload = sr.ReadToEnd(); JSONClass json = JSON.Parse(payload).AsObject; if (json != null && json.ContainsKey("ConnectionToken")) { _connectionToken = Uri.EscapeDataString(json["ConnectionToken"].Value); onConnectionUpdate(ConnectionStatus.CONNECTED); } else { onConnectionUpdate(ConnectionStatus.NOT_CONNECTED); } } Open(); } catch (Exception e) { onConnectionUpdate(ConnectionStatus.NOT_CONNECTED); } }
void _ws_OnMessage(object sender, MessageEventArgs e) { JSONClass json = JSON.Parse(e.Data).AsObject; #if UNITY_EDITOR UnityEngine.Debug.Log(e.Data); #endif if (json.ContainsKey("E")) { UnityMainThreadDispatcher.Instance().Enqueue(() => onConnectionUpdate(ConnectionStatus.ERROR)); } else { UnityMainThreadDispatcher.Instance().Enqueue(() => onConnectionUpdate(ConnectionStatus.CONNECTED)); var msgs = SignalRMessage.FromJSON(json); foreach (var msg in msgs) { switch (msg.M) { case "remoteCommand": RemoteCommand cmd = (RemoteCommand)System.Enum.Parse(typeof(RemoteCommand), msg.A[0].ToUpper()); var param = msg.A.Length > 1 ? msg.A[1] : string.Empty; UnityMainThreadDispatcher.Instance().Enqueue(() => onRemoteCommand(cmd, param)); break; } } } }
/// <summary> /// Please note that with the <see cref="SimpleJSON"/> system key-value associations are actually instances of <see cref="JSONClass"/>. /// </summary> /// <param name="key"></param> /// <returns></returns> public JSONNode this[string key] { get { if (json == null) { throw new Exception("JSONClass is not ready!"); } if (!json.ContainsKey(key)) { return(null); } return(json[key]); } set { json[key] = value; } }
public void AnalizeText(string text) { text = CleanText(text); string[] ss = text.Split(" "[0]); Dictionary <int, JSONClass> statuses = new Dictionary <int, JSONClass>(); foreach (string s in ss) { KeyValuePair <int, string> kvp = db.GetWordStatus(s); statuses[kvp.Key] = JSON.Parse(kvp.Value).AsObject; } foreach (KeyValuePair <int, JSONClass> kvp in statuses) { int id = kvp.Key; JSONClass obj = kvp.Value; foreach (KeyValuePair <int, JSONClass> kvp2 in statuses) { int id2 = kvp2.Key; int position = GiveWordPosition(statuses, obj, kvp2.Value); if (kvp.Value == kvp2.Value) { continue; } if (!obj.ContainsKey(position.ToString())) { obj.Add(position.ToString(), new JSONClass()); } JSONClass score = obj[position.ToString()].AsObject; if (!score.ContainsKey(id2.ToString())) { score.Add(id2.ToString(), new JSONData(0)); } int currentScore = score[id2.ToString()].AsInt; currentScore++; score[id2.ToString()] = new JSONData(currentScore); } } foreach (KeyValuePair <int, JSONClass> kvp in statuses) { int id = kvp.Key; JSONClass obj = kvp.Value; db.UpdateWord(id, obj.ToString()); } }