1

Goodmorning all .I am beginner in Xamarin.Forms. I am trying to learn how to get data in Listview with webservices.

My json format :

{ "contacts": [ { "name": "Clark Kent", "email": "[email protected]" }, { "name": "Bruce Wayne", "email": "[email protected]" }, { "name": "Tony Stark", "email": "[email protected]" }, ] }

I want to get this Data in Listview. Please help How to call Url and this data in Listview. Thanks in advance.

1 Answer 1

2

Just deserialize your json data and bind that deserialized json data to your listview.

xaml.cs page:

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

xaml page:

<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>
Sign up to request clarification or add additional context in comments.

1 Comment

can you provide project setup?@Hitesh patil

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.