public User(string jsonString) : this() { JsonObject jsonObject = JsonObject.Parse(jsonString); Id = jsonObject.GetNamedString(idKey, ""); IJsonValue phoneJsonValue = jsonObject.GetNamedValue(phoneKey); if (phoneJsonValue.ValueType == JsonValueType.Null) { Phone = null; } else { Phone = phoneJsonValue.GetString(); } Name = jsonObject.GetNamedString(nameKey, ""); Timezone = jsonObject.GetNamedNumber(timezoneKey, 0); Verified = jsonObject.GetNamedBoolean(verifiedKey, false); foreach (IJsonValue jsonValue in jsonObject.GetNamedArray(educationKey, new JsonArray())) { if (jsonValue.ValueType == JsonValueType.Object) { Education.Add(new School(jsonValue.GetObject())); } } }
/// <summary> /// Reads the education section from the profile XML. /// </summary> /// <param name="reader">The XML reader.</param> /// <param name="education">The education.</param> private static void ReadEducationSection(XmlReader reader, Education education) { var school = new School(); while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element) { continue; } if (reader.Name == "employmentHistory") { break; } if (reader.Name == "school" && reader.HasAttributes) { school.Name = reader.GetAttribute("name"); CertificateType certificateType; Enum.TryParse(reader.GetAttribute("certificateType"), true, out certificateType); school.Certificate = certificateType; continue; } if (reader.Name == "headline") { school.Headline = reader.ReadElementContentAsString(); continue; } if (reader.Name == "description") { school.Description = reader.ReadElementContentAsString(); continue; } if (reader.Name == "start" && reader.HasAttributes) { school.StartMonth = Convert.ToInt32(reader.GetAttribute("month")); school.StartYear = Convert.ToInt32(reader.GetAttribute("year")); continue; } if (reader.Name == "end" && reader.HasAttributes) { school.EndMonth = Convert.ToInt32(reader.GetAttribute("month")); school.EndYear = Convert.ToInt32(reader.GetAttribute("year")); } education.Add(school); } }