public User(JsonObject jsonObj) : base(jsonObj) { }
public Checkin(JsonObject jsonObj) : base(jsonObj) { }
public Group(JsonObject jsonObj) : base(jsonObj) { }
public CheckinGroup(JsonObject jsonObj) : base(jsonObj) { }
public CheckinEvent(JsonObject obj) : base(obj) { }
public void ParseFromObject(JsonObject obj) { Type thisType = this.GetType(); var props = thisType.GetProperties(); foreach (var key in obj.Keys) { object keyValue = obj[key]; if (keyValue == null) { continue; } RawProperties[key] = keyValue.ToString(); PropertyInfo targetPropInfo = null; foreach (var p in props) { string jsonPropertyName = p.Name; var attributes = p.GetCustomAttributes(true).ToList(); foreach (var atr in attributes) { JsonPropertyAttribute jpa = atr as JsonPropertyAttribute; if (jpa != null) { jsonPropertyName = jpa.JsonPropertyID; } } if (key.ToUpperInvariant() == jsonPropertyName.ToUpperInvariant()) { targetPropInfo = p; } } if (targetPropInfo != null) { if (targetPropInfo.PropertyType == typeof(DateTime) || targetPropInfo.PropertyType == typeof(DateTime?)) { if (keyValue != null) { if (keyValue.GetType() == typeof(string)) { keyValue = ((string)keyValue).Replace("(EST)", "-05"); keyValue = ((string)keyValue).Replace("(CEST)", "-05"); keyValue = ((string)keyValue).Replace("(EDT)", "-05"); keyValue = ((string)keyValue).Replace("(CST)", "-06"); keyValue = ((string)keyValue).Replace("(CDT)", "-06"); keyValue = ((string)keyValue).Replace("(MST)", "-07"); keyValue = ((string)keyValue).Replace("(MDT)", "-07"); keyValue = ((string)keyValue).Replace("(PST)", "-08"); keyValue = ((string)keyValue).Replace("(PDT)", "-08"); keyValue = ((string)keyValue).Replace("(IST)", "+05"); keyValue = ((string)keyValue).Replace("(GMT)", "+00"); try { keyValue = DateTime.Parse(keyValue.ToString()); } catch { } } } } if (targetPropInfo.PropertyType.IsSubclassOf(typeof(CityObject))) { object newInstance = Activator.CreateInstance(targetPropInfo.PropertyType, keyValue); targetPropInfo.SetValue(this, newInstance, null); } else if (keyValue.GetType() == typeof(DateTime) && targetPropInfo.PropertyType == typeof(DateTime?)) { targetPropInfo.SetValue(this, keyValue, null); } else if (targetPropInfo.PropertyType == typeof(bool?)) { bool result = false; if (bool.TryParse(keyValue.ToString(), out result)) { targetPropInfo.SetValue(this, result, null); } } else if (targetPropInfo.PropertyType == typeof(int?)) { int result = 0; if (Int32.TryParse(keyValue.ToString(), out result)) { targetPropInfo.SetValue(this, result, null); } } else { targetPropInfo.SetValue(this, Convert.ChangeType(keyValue, targetPropInfo.PropertyType), null); } } } }
internal CityObject(JsonObject obj) { ParseFromObject(obj); }
public Barcode(JsonObject jsonObj) : base(jsonObj) { }
protected dynamic ParseObject() { Read(); //read first { ReadWhitespace(); dynamic obj = new JsonObject(); var doRead = true; while (doRead) { switch (Peek()) { case -1: ParseError("Unterminated object before end of json string."); return obj; case ',': Read(); break; case '}': Read(); doRead = false; break; case '"': var key = ParseString(); if (CamelizeProperties) { _sb.Clear(); if (key.Contains('_')) { var words = key.Split('_'); foreach (var w in words) { _sb.Append(w.Substring(0, 1).ToUpper()); _sb.Append(w.Substring(1, w.Length - 1).ToLower()); } } else { _sb.Append(key.Substring(0, 1).ToUpper()); _sb.Append(key.Substring(1, key.Length - 1).ToLower()); } key = _sb.ToString(); } ReadWhitespace(); ReadExpect(':'); ReadWhitespace(); var val = ParseValue(); obj[key] = val; break; default: ReadWhitespace(); break; } } return obj; }