Я получаю ошибку,помогите решить вопрос
Oшибка
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'statistic_proj.Model.ContactList' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
JsonContacts.cs
public class Contactss
{
[JsonProperty("provinceState")]
public string ProvinceState { get; set; }
[JsonProperty("countryRegion")]
public string CountryRegion { get; set; }
[JsonProperty("fips")]
public string Fips { get; set; }
}
public class ContactList
{
public List<Contact> contacts { get; set; }
}
MainPage.xaml.cs
public async void GetJSON()
{
//Check network status
if (NetworkCheck.IsInternet())
{
var client = new System.Net.Http.HttpClient();
var response = await client.GetAsync("");
string contactsJson = await response.Content.ReadAsStringAsync();
ContactList ObjContactList = new ContactList();
if (contactsJson != "")
{
//Converting JSON Array Objects into generic list
ObjContactList = JsonConvert.DeserializeObject <ContactList>(contactsJson.ToString());
}
//Binding listview with server response
listviewConacts.ItemsSource = ObjContactList.contacts;
}
else
{
await DisplayAlert("JSONParsing", "No network is available.", "tttt");
}
//Hide loader after server response
ProgressLoader.IsVisible = false;
}
MainPage.xaml
<ListView x:Name="listviewConacts" Grid.Row="1" HorizontalOptions="FillAndExpand" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid HorizontalOptions="FillAndExpand" Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Text="{Binding ProvinceState}" HorizontalOptions="StartAndExpand" Grid.Row="0" TextColor="Blue" FontAttributes="Bold"/>
<Label Text="{Binding CountryRegion}" HorizontalOptions="StartAndExpand" Grid.Row="1" TextColor="Orange" FontAttributes="Bold"/>
<Label Text="{Binding Fips}" HorizontalOptions="StartAndExpand" Grid.Row="2" TextColor="Gray" FontAttributes="Bold"/>
<BoxView HeightRequest="2" Margin="0,10,10,0" BackgroundColor="Gray" Grid.Row="3" HorizontalOptions="FillAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
JSON
[
{
"provinceState": null,
"countryRegion": "Spain",
"lastUpdate": 1588455152000,
"lat": 40.463667,
"long": -3.74922,
"confirmed": 213435,
"recovered": 112050
},
{
"provinceState": null,
"countryRegion": "Italy",
"lastUpdate": 1588455152000,
"lat": 41.87194,
"long": 12.56738,
"confirmed": 209328,
"recovered": 79914
},
{
"provinceState": null,
"countryRegion": "United Kingdom",
"lastUpdate": 1588455152000,
"lat": 55.3781,
"long": -3.436,
"confirmed": 182260,
"recovered": 0
},
{
"provinceState": "New York",
"countryRegion": "US",
"lastUpdate": 1588455152000,
"lat": 40.7672726,
"long": -73.97152637,
"confirmed": 172354,
"recovered": 0,
},
]