Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
{"$id":"1","Version":"1.0.0","dateTime":"2020/07/31 09:03:05","StatusCode":1,"ErrorMessage":"Success","Result":{"$id":"2","getpartnumberover":[{"$id":"3","partnumber":"14312-054-1","productname":"fill-line-hose-assy"}]}}


Please see the above json

Xaml Code

<ListView x:Name="MyListView" ItemsSource="{Binding MyListView}">
           <ListView.ItemTemplate>
               <DataTemplate>
                   <ViewCell>

                       <StackLayout Orientation="Horizontal" Margin="5" HeightRequest="90">

                           <Label Text="{Binding partnumber}" TextColor="Black"></Label>


                       </StackLayout>
                   </ViewCell>

               </DataTemplate>
           </ListView.ItemTemplate>
       </ListView>



Data is not getting bind and c# code is working fine but the mobile app is showing the blank page

What I have tried:

using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json");
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");


                var response = httpClient.GetAsync("APi url").Result;
                string stud = response.Content.ReadAsStringAsync().Result;
                JToken m = JToken.Parse(stud);
                JArray men = (JArray)m.SelectToken("Result.over");
                foreach (var zaq in men)
                {
                    MyListView.ItemsSource = zaq.SelectToken("partnumber").ToString();
                }
            }
Posted
Updated 7-Aug-20 6:11am

.ItemsSource takes a "list" (i.e. collection), not a (single) "string".

ListView Data Sources - Xamarin | Microsoft Docs[^]
 
Share this answer
 
Comments
sonutool 1-Aug-20 4:54am    
I have tried this its not working @gerry
I have add the list class from json class and then its working
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900