consume rest web service in TextBlocks

hanali

I want to consume a rest web service that shows the name of each cuisine in stackPanels in my Grid like this:

enter image description here

but with my code,I get only the last element,How can I send each name of kitchen in a stackPanel ,this is my code:

<Grid x:Name="Grid1" >
            <StackPanel Orientation="Horizontal">
                <StackPanel Orientation="Horizontal" >
                    <TextBlock Text="{Binding Path=nom}"        x:Name="nomCuisine"/> 
                </StackPanel>
            </StackPanel>
        </Grid>

and this is my function:

 private async void GetListeCuisines()
        {
            UriString2 = "URL/cuisines.php";
            var http = new HttpClient();
            http.MaxResponseContentBufferSize = Int32.MaxValue;
            var response = await http.GetStringAsync(UriString2);
            var rootObject = JsonConvert.DeserializeObject<Barberry.Models.RootObject>(response);
             for(int i=0; i < 2;i++)
            {
                nomCuisine.Text = rootObject.cuisines[i].nom;
            }
        }

this is my json data:

success: 1,
message: "cuisine found!",
cuisines: [
{
id: "1",
nom: "Cuisine 1"
},
{
id: "2",
nom: "Cuisine 2"
}
]

thanks for help

Update:

I set my code to this:

<ListView ItemsSource="{Binding items}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                    <StackPanel Orientation="Horizontal" >
                    <TextBlock Text="" x:Name="nomCuisine"/> 
                    </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

and this is the function:

private async void GetListeCuisines()
        {
            UriString2 = "myURL/cuisines.php";
            var http = new HttpClient();
            http.MaxResponseContentBufferSize = Int32.MaxValue;
            var response = await http.GetStringAsync(UriString2);
            var rootObject = JsonConvert.DeserializeObject<Barberry.Models.RootObject>(response);
             for(int i=0; i < 2;i++)
            {
                string items= rootObject.cuisines[i].nom;
            }}

this time I get nothing as a result :(

Thomas LEBRUN

You can use the following code:

<ListView x:Name="cuisineListview">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" >
                <TextBlock Text="{Binding nom}" x:Name="nomCuisine"/> 
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

And:

private async void GetListeCuisines()
{
    UriString2 = "myURL/cuisines.php";
    var http = new HttpClient();
    http.MaxResponseContentBufferSize = Int32.MaxValue;
    var response = await http.GetStringAsync(UriString2);
    cuisineListview.ItemsSource = JsonConvert.DeserializeObject<Barberry.Models.RootObject>(response).cuisines;
}

But I suggest you to learn how to use MVVM so you can have cleaner code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating ABL Client to Consume a REST Web Service

From Dev

How to consume Rest Web service in c#

From Dev

How to consume a rest web service in phonegap for android?

From Dev

Consume REST Service in XPage

From Dev

Spring consume rest json web-service error

From Dev

Unable to consume web service

From Dev

Grails 2.4.3: Consume a REST Service

From Dev

Consume REST service in MVC 6

From Dev

Trying to consume Web Service class

From Dev

Consume web service returning list

From Dev

Consume REST service in server-based agent

From Dev

Consume REST service in server-based agent

From Dev

Consume .NET web service in Codename One

From Dev

Consume a simple web service using mule

From Dev

Consume SOAP based web service with https

From Dev

How to consume a JSON web service in Java

From Dev

Consume multiple resources in a RESTful Web Service

From Dev

AngularJS: consume web service from Wikipedia API

From Dev

To consume a web service with multiple input arguments in mule

From Dev

consume SOAP local web service in android

From Dev

how to consume the json web service in objective c?

From Dev

How to consume a web service with headers C #?

From Dev

How to Consume an RPC-Style Web Service with a WCF Service Reference?

From Dev

login in REST web service

From Dev

Rest Web Service with scala

From Dev

Spring Framework & RestTemplate: not being able to consume REST Service

From Dev

Spark SQL: How to consume json data from a REST service as DataFrame

From Dev

Why can't AngularJS app consume REST service on different server?

From Dev

What is the simplest way to consume an external REST service in Lagom?

Related Related

HotTag

Archive