I'm working in Xamarin and have a nested json object (which is a list of items starting at "message") that I need to add to an ObservableCollection, but I'm having trouble assigning it to the collection. The data is getting retrieved fine, but I keep getting this error:
cannot convert from 'RequestorPerformer.Models.BaseVenue[]' to 'System.Collections.Generic.IEnumerable<RequestorPerformer.Models.Rootobject>'
The model:
public class BaseVenue
{
public int Id { get; set; }
public string VenueName { get; set; }
public string VenueAddress { get; set; }
public string ShowDate { get; set; }
public string ShowTime { get; set; }
public string Description { get; set; }
}
public class Rootobject
{
public bool Error { get; set; }
public int ErrorCode { get; set; }
public BaseVenue[] Message { get; set; }
}
The code (the line, "_posts = new ..." is where I'm getting the error) :
private ObservableCollection<Rootobject> _posts;
var posts = JsonConvert.DeserializeObject<Rootobject>(returnResponse);
_posts = new ObservableCollection<Rootobject>(posts.Message);
The data (what's in returnResponse):
{
"error": false,
"errorCode": 0,
"message": [{
"id": "93",
"venueName": "Sushi Kuni",
"venueAddress": "10211 S De Anza Blvd Cupertino CA",
"showDate": "1531022400",
"showTime": "",
"description": ""
}, {
"id": "38",
"venueName": "Two Keys Tavern",
"venueAddress": "333 S Limestone Lexington KY",
"showDate": "1531368000",
"showTime": "8 pm - 1 am",
"description": ""
}, {
"id": "39",
"venueName": "Two Keys Tavern",
"venueAddress": "333 S Limestone Lexington KY",
"showDate": "1531454400",
"showTime": "8 pm - 2 am",
"description": ""
}]
}
Even if I remove the posts.Message and just make it post I get the same basic error message:
cannot convert from 'RequestorPerformer.Models.Rootobject' to 'System.Collections.Generic.IEnumerable<RequestorPerformer.Models.Rootobject>'
Thank you in advance,
Robert