我想通过webapi从数据库中获取数据并在listview中显示,但是对于lsitview我想使用分页。我正在使用syncfusion用于listview分页。我已经做了一些工作,但是我遇到了错误
我遇到的错误是“无法反序列化当前JSON对象(例如{“ name”:“ value”})为类型“ System.Collections.Generic.List`1”
private List<products> products = new List<products>();
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync("http://orangepotato.rjcpacking.com/index.php?route=api/login/getFeaturedProducts");
protected async void FeaturedList()
{ products = JsonConvert.DeserializeObject<List<products>>(json);
dataPager.Source = products;
}
void Handle_OnDemandLoading(object sender, Syncfusion.SfDataGrid.XForms.DataPager.OnDemandLoadingEventArgs e)
{
var source= products.Skip(e.StartIndex).Take(e.PageSize);
FeaturedlistView.ItemsSource = source.AsEnumerable();
}
答案 0 :(得分:0)
服务返回的json是包含列表的对象。您不能直接将其反序列化为列表
使用json2csharp.com,我得到了用于json的模型
public class Product
{
public string product_id { get; set; }
public string thumb { get; set; }
public string name { get; set; }
public string price { get; set; }
public string special { get; set; }
public int rating { get; set; }
public string discount_percentage { get; set; }
}
public class RootObject
{
public List<Product> products { get; set; }
}