Forum Xamarin.Forms

Webservice data is not displaying in emulator

DarshanJSDarshanJS USMember ✭✭✭✭

Hi guys, i am trying bind data from webservice but when run the application it will keeps on loading in emulator
i am not aware what is the problem i have shared snapshot

and code please help me

public async void GetJSON()
        //Check network status   
        if (NetworkCheck.IsInternet())

            var client = new System.Net.Http.HttpClient();
            var response = await client.GetAsync("");
            string contactsJson = await response.Content.ReadAsStringAsync();
            ContactList ObjContactList = new ContactList();
            if (contactsJson != "")
                //Converting JSON Array Objects into generic list  
                ObjContactList = JsonConvert.DeserializeObject<ContactList>(contactsJson);
            //Binding listview with server response    
            listviewConacts.ItemsSource = ObjContactList.contacts;
            await DisplayAlert("JSONParsing", "No network is available.", "Ok");
        //Hide loader after server response    
        ProgressLoader.IsVisible = false;

Best Answer


  • DarshanJSDarshanJS USMember ✭✭✭✭

    Guys anyone please answer for this question i have stuck in this from two days

  • VenkataSwamyVenkataSwamy INMember ✭✭✭

    Hi @DarshanJS

    Might be problem with ActivityIndicator in XAML

    Before calling web service you need to put IsRunning="true" after getting response put IsRunning="false"

    the below code useful for thank you

         <Grid AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            <Label Grid.Row="0" Margin="10" Text="JSON Parsing" FontSize="25" />
            <ListView x:Name="listviewConacts" Grid.Row="1" HorizontalOptions="FillAndExpand" HasUnevenRows="True" >
                            <Grid HorizontalOptions="FillAndExpand" Padding="10">
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                <Label Text="{Binding name}" HorizontalOptions="StartAndExpand" Grid.Row="0" TextColor="Blue"  FontAttributes="Bold"/>
                                <Label Text="{Binding email}" HorizontalOptions="StartAndExpand" Grid.Row="1" TextColor="Orange"  FontAttributes="Bold"/>
                                <Label Text="{Binding}" HorizontalOptions="StartAndExpand" Grid.Row="2" TextColor="Gray"  FontAttributes="Bold"/>
                                <BoxView HeightRequest="2" Margin="0,10,10,0" BackgroundColor="Gray" Grid.Row="3" HorizontalOptions="FillAndExpand" />
         <ActivityIndicator x:Name="ProgressLoader" Color="Black" VerticalOptions="CenterAndExpand" 
         AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"/>
  • DarshanJSDarshanJS USMember ✭✭✭✭

    @Norman Mackay
    when i debug it is not going to next line after this line

    var response = await client.GetAsync("");

    what may be the issue as you said whether it is a DNS issue or web service issue

  • DarshanJSDarshanJS USMember ✭✭✭✭

    @NMackay said:

    Actually i was facing internet connection issue in Android emulator instead of running the app in built in emulator, i tried to run the application by creating new AVD using Android SDK now it is working fine

  • NMackayNMackay GBInsider, University mod


    Yeah, the build it emulators are a waste of time for anything but basic demos

Sign In or Register to comment.