【问题标题】:How to get Json Data in Listview Xamarin.Forms?如何在 Listview Xamarin.Forms 中获取 Json 数据?
【发布时间】:2017-06-29 05:38:21
【问题描述】:

大家早上好。我是 Xamarin.Forms 的初学者。我正在尝试学习如何使用 Web 服务在 Listview 中获取数据。

我的json格式:

{ "contacts": [ { "name": "Clark Kent", "email": "mmguy@planet.com" }, { "name": "Bruce Wayne", "email": "ceo@wayne.net" }, { "name": "Tony Stark", "email": "playboy@stark.com" }, ] }

我想在 Listview 中获取此数据。请帮助如何在 Listview 中调用 Url 和此数据。提前致谢。

【问题讨论】:

    标签: xaml xamarin xamarin.forms


    【解决方案1】:

    只需反序列化您的 json 数据并将反序列化的 json 数据绑定到您的列表视图。

    xaml.cs 页面:

    IEnumerable<ContactModel> contactList {get; set;}
    contactList = JsonConvert.DeserializeObject<IEnumerable<ContactModel>>(json);
    var listView = new ListView();
    listView.ItemsSource =contactList;
    

    xaml 页面:

    <ListView  x:Name="listView">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout BackgroundColor="#eee"
                        Orientation="Vertical">
                            <Label Text="name"/>
                            <Label Text="email"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    

    【讨论】:

    • 你能提供项目设置吗?@Hitesh patil
    猜你喜欢
    • 1970-01-01
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多