public override IList <EFRegion> ReadJson(JsonReader reader, Type objectType, IList <EFRegion> existingValue, bool hasExistingValue, JsonSerializer serializer) { IList <EFRegion> result = (existingValue == null ? new List <EFRegion>() : existingValue); JObject o = serializer.Deserialize <JObject>(reader); JArray provinces = o["province"] as JArray; EFCity city; EFRegion region; foreach (JObject province in provinces) { region = new EFRegion(); region.Name = (string)province["name"]; foreach (JObject cityObject in province["city"]) { city = new EFCity(); city.Name = (string)cityObject["name"]; region.AppendCity(city); } result.Add(region); } return(result); }
public override EFRegion ReadJson(JsonReader reader, Type objectType, EFRegion existingValue, bool hasExistingValue, JsonSerializer serializer) { EFRegion result = (existingValue == null ? new EFRegion() : existingValue); JObject o = serializer.Deserialize <JObject>(reader); //{{"province": [{"city": [{"name": "Pretoria"}, { "name": "Johannesburg"}, { "name": "Cullinan"}], "name": "Gauteng"}]}} string provinceName = (string)o["province"][0]["name"]; result.Name = provinceName; EFCity city; foreach (JObject cityObject in o["province"][0]["city"]) { city = new EFCity(); city.Name = (string)cityObject["name"]; result.AppendCity(city); } return(result); }
protected override void OnAppearing() { base.OnAppearing(); EFCity context = this.BindingContext as EFCity; this.lblCityName.Text = context.Name; this.Title = context.region.Name; }
public EFCity marshallCity(string json) { EFCity result = null; try { JsonSerializerSettings settings = new JsonSerializerSettings(); settings.Converters.Add(new CityConverter()); result = JsonConvert.DeserializeObject <EFCity>(json, settings); } catch (Exception e) { Console.WriteLine($"marshallCity failed with: {e.Message}"); } return(result); }