小编tba*_*t17的帖子

Xamarin表单读取本地json文件并显示在选择器中

我正在尝试将联系人的 json 文件解析为列表,并在显示联系人姓名的页面上的选择器中向用户显示该列表。

我的项目根目录中有一个名为“contacts.json”的 json 文件,其构建操作设置为嵌入资源。

我的 contact.json 文件

{
  "contacts": [
    {
      "name": "JOE",
      "email": "name@handle",
      "phoneNumber": "123-456-7890"
    },
    {
      "name": "JYM",
      "email": "name@handle",
      "phoneNumber": "123-456-7890"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我的联系方式:

    public partial class RootObject
    {
        [JsonProperty("contacts")]
        public List<Contact> Contacts { get; set; }
    }

    public partial class Contact
    {
        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("email")]
        public string Email { get; set; }

        [JsonProperty("phoneNumber")]
        public string PhoneNumber { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

我的页面视图模型,我在其中实现了 json 解析器

    public partial …
Run Code Online (Sandbox Code Playgroud)

c# data-binding json picker xamarin.forms

4
推荐指数
1
解决办法
5970
查看次数

标签 统计

c# ×1

data-binding ×1

json ×1

picker ×1

xamarin.forms ×1