public override void Add(string aKey, JSONNode aItem) { var tmp = new JSONClass(); tmp.Add(aKey, aItem); Set(tmp); }
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[string aKey] { get { return new JSONLazyCreator(this, aKey); } set { var tmp = new JSONClass(); tmp.Add(aKey, value); Set(tmp); } }
public static bool Register(string appKey, string appSecret) { _appKey = appKey; _appSecret = appSecret; string url = new UrlBuilder() .SetPath("/ActiveConfig/v1/Register/") .AddParam("appid", _appKey) .AddParam("secretkey", _appSecret) .GetUrl(); JSONClass deviceInfo = new JSONClass(); deviceInfo.Add("sys", new JSONData("WindowsPhone")); deviceInfo.Add("version", new JSONData(Environment.OSVersion.Version.ToString())); deviceInfo.Add("language", new JSONData(System.Threading.Thread.CurrentThread.CurrentCulture.Name)); deviceInfo.Add("resolution", new JSONData(Application.Current.Host.Content.ActualWidth + "*" + Application.Current.Host.Content.ActualHeight)); deviceInfo.Add("carrier", new JSONData(Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.CellularMobileOperator ?? "")); string body = string.Format("appid={0}&secretkey={1}&info={2}", _appKey, _appSecret, deviceInfo.ToString()); Http.PostStringAsync(url, body, (s, e) => { if (e == null) { var dict = JSON.Parse(s); if (dict != null) { string code = dict["code"].Value; string msg = dict["msg"].Value; string data = dict["data"].Value; if (code != "0") { Debug.WriteLine("Server return error {0}: {1}", code, msg); return; } } } else { Debug.WriteLine(e.Message); } }); _updateTimer = new Timer(OnTimer, null, _updateInterval, _updateInterval); _isRegistered = true; return false; }