Error: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.ObjectModel.ObservableCollection
1[System.Collections.ObjectModel.ObservableCollection
1[DynamicLayoutSample.ElementList]]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'page', line 1, position 8.
Got this error while fetching data from web service using refit in xamarin forms.below the model class
public class ApiResponse
{
[JsonProperty(PropertyName = "page")]
public ObservableCollection<ObservableCollection<ElementList>> items { get; set; }
}
public class ElementList
{
[JsonProperty("page")]
public string page { get; set; }
[JsonProperty("name")]
public string name { get; set; }
[JsonProperty("objectid")]
public string objectid { get; set; }
[JsonProperty("width")]
public string width { get; set; }
[JsonProperty("height")]
public string height { get; set; }
[JsonProperty("top")]
public string top { get; set; }
[JsonProperty("left")]
public string left { get; set; }
[JsonProperty("transform")]
public string transform { get; set; }
[JsonProperty("backgroundcolor")]
public string backgroundcolor { get; set; }
}
and my json is,
{
"page": [
[
{
"page": "2",
"name": "element",
"objectid": "rectelement_1",
"width": "29%",
"height": "9%",
"top": "21%",
"left": "15%",
"transform": "0deg",
"backgroundcolor": "rgb(0, 0, 0)"
},
{
"page": "2",
"name": "element",
"objectid": "circleelement_1",
"width": "33%",
"height": "12%",
"top": "20%",
"left": "44%",
"transform": "0deg",
"backgroundcolor": "rgb(0, 0, 0)"
}
]
]
}
Service call method,
ObservableCollection<ObservableCollection<ElementList>> result { get; set; }
result = new ObservableCollection<ObservableCollection<ElementList>>();
result = await api_interface.GetElements();
and this is my interface
interface ApiInterface
{
[Get("/magazine_pagevalue.php?mid=1&issueno=1")]
Task<ObservableCollection<ObservableCollection<ElementList>>> GetElements();
}