如何在 Xamarin.forms 列表视图中显示 JSON 数据? [英] How to display JSON data in Xamarin.forms list view?

查看:37
本文介绍了如何在 Xamarin.forms 列表视图中显示 JSON 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 xamarin.forms 的新手,我想构建一个跨平台的应用程序,它将在列表视图中显示 JSON 数据.这是我的 JSON 数据.

I am new to xamarin.forms, and i want to build an cross platform app that will display JSON data in the list view. This is my JSON data.

{
  "fish_product": [
    {
      "fish_id": "1",
      "fish_img": "",
      "fish_name": "Indian Mackerel",
      "fish_category": "Marine Fish",
      "size": "Medium",
      "price": "100"
    },
    {
      "fish_id": "2",
      "fish_img": "",
      "fish_name": "Manthal Repti",
      "fish_category": "Marine Fish",
      "size": "Small",
      "price": "200"
    },
    {
      "fish_id": "4",
      "fish_img": "",
      "fish_name": "Baby Sole Fish",
      "fish_category": "Marine Fish",
      "size": "Small",
      "price": "600"
    }
 ]
}

我想在列表视图中显示fish_name".请为此提出任何解决方案或任何文章或教程.提前致谢.

I want to display "fish_name" in list view. please suggest any solution or any article or tutorial for this. thank you in advance.

推荐答案

我觉得这可能对你有帮助

I think this may help you

您的模型

public class FishProduct
{
    public string fish_id { get; set; }
    public string fish_img { get; set; }
    public string fish_name { get; set; }
    public string fish_category { get; set; }
    public string size { get; set; }
    public string price { get; set; }
}

public class RootObject
{
    public List<FishProduct> fish_product { get; set; }
}

Web 服务调用和 JSON 反序列化

Webservice call and JSON Deserialisation

public async Task GetData()
{
 try
  {
  HttpClient client = new HttpClient();
  var result = await client.GetAsync("http://yourJSON_Url");
  result.EnsureSuccessStatusCode();
  string json = await result.Content.ReadAsStringAsync();
  List<FishProduct>  res= JsonConvert.DeserializeObject<List<FishProduct>>(json);

  }
 catch (Exception ex)
 {
   throw;
  }
}

这篇关于如何在 Xamarin.forms 列表视图中显示 JSON 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆