【问题标题】:How to get json data from web api paging listview paging syncfusion for xamarin forms?如何从 web api 分页列表视图分页同步融合中获取 xamarin 表单的 json 数据?
【发布时间】:2019-03-29 03:35:25
【问题描述】:

我想通过 webapi 从数据库中获取数据并显示在 listview 中,但是使用 lsitview 我想使用分页。我正在使用 syncfusion 进行列表视图分页。我已经完成了一些工作,但我遇到了错误

我得到的错误是“无法将当前 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();
        }

【问题讨论】:

    标签: xamarin.forms syncfusion


    【解决方案1】:

    服务返回的 json 是一个包含列表的对象。您不能将其直接反序列化为 List

    使用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; }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      相关资源
      最近更新 更多