I am trying to parse a JSON Array with no success.I researched all possible solutions but none seems to work for my solution.
This is the JSON returning from server:
{"events":[{"url":"xxxxx","title":"xxxxx","date":"xxxx","time":"xxxx"},{"url":"xxxxx","title":"xxxxx","date":"xxxx","time":"xxxx"}]}
This is my RootObject class :
public class ChristmasEvent
{
[JsonProperty("events")]
public List<Event> Events { get; set; }
}
public class Event
{
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("date")]
public string Date { get; set; }
[JsonProperty("time")]
public string Time { get; set; }
}
Web Service class
private const string Url = "http://xxxx/events";
private HttpClient _httpClient = new HttpClient();
var apiResource = await _httpClient.GetStringAsync(Url);
var tr = JsonConvert.DeserializeObject<List<ChristmasEvent>>(apiResource);
ObservableCollection<ChristmasEvent> christmasEvents = new ObservableCollection<ChristmasEvent>(tr);
EventListView.ItemsSource = christmasEvents;
XAML File
<ListView x:Name="EventListView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding title}" />
<Label Text="{Binding date, StringFormat='{0:MMMM dd, yyyy}'}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I am unsure why this is not working and seeking to find what i am doing wrong..