locked
HttpClient returns blank from json data RRS feed

  • Question

  • Hi, 

    am trying base reading from json within my Xamarin app using below code:

    public class Details
    {  
        public string bio_text { get; set; }  
    }  
    
    

    private async void GetBio()
    {
        var RestURL = "https://www.softnames.com/mybio/ws/get_person_bio.php?id=1";
    
        HttpClient client = new HttpClient(new NativeMessageHandler());
        HttpResponseMessage response = await client.GetAsync(RestURL);
    
        using (HttpContent content = response.Content)
        {
            string result = await content.ReadAsStringAsync();
            var Items = JsonConvert.DeserializeObject<Details>(result);
    
            console.log(Items.bio_text);
        }
    }
    

    but the bio_text returns blank and I am not getting any data returned although I can see the data when I paste the above url in any browser.

    WHat's the problem here please?

    Thanks,

    Jassim


    Saturday, October 28, 2017 6:41 PM

All replies

  • Check that result contains the expected response. If it is an array, then try this:

       var Items = JsonConvert.DeserializeObject<Details[]>(result);
       console.log(Items[0].bio_text);


    Sunday, October 29, 2017 9:26 AM
  • Hi Jassim Rahma,

    Thank you for posting here.

    For your question is more related to Xamarin, you could post a new thread in Xamarin forum for suitable support.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions. 

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 31, 2017 2:19 AM
  • Hi Jassim,

    What you get from below code is an array, so try Viorel_'s solution, it works.

    string result = await content.ReadAsStringAsync();

    Best Regards,

    Charles He


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, November 3, 2017 10:37 AM