Xamarin Forms reading JSON

So I am retrieving JSON data from my site and this is my code:

The model:

    class Reservations
    {
        public string id_reservation { get; set; }
        public string spz { get; set; }
        public string reservation_day { get; set; }
        public string reservation_time { get; set; }
        public string ip_address { get; set; }
    }

The connection and parsing:

protected async void CheckReservations(string day)
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                try
                {
    private const string Url = "Urltomysite";
        private HttpClient _client = new HttpClient();
                    var content = await _client.GetStringAsync(Url);
                    List<Reservations> myData = JsonConvert.DeserializeObject<List<Reservations>>(content);
                foreach (Reservations res in myData)
                {
                    System.Console.WriteLine("Time:" + res.reservation_time);
                }

            }
            catch (Exception e)
            {
                Debug.WriteLine("" + e);
            }
        }
    }

And the JSON response from my site:

[
{
id_reservation: “39”,
spz: “NRGH67L”,
reservation_day: “2019-01-26”,
reservation_time: “14:00”,
ip_address: “192.168.137.5”
}
]

But when I try to print the reservation_time from List of the Object in the foreach I dont get any results. I am still pretty new to this and got this far from tutorials, so dont know what I am missing.

Thanx for any replies.

#json #xamarin

5 Likes45.35 GEEK