HttpClient从json数据返回空白 [英] HttpClient returns blank from json data

查看:410
本文介绍了HttpClient从json数据返回空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

am使用以下代码在我的Xamarin应用程序中尝试从json读取基础:

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);
    }
}

但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是请问这里有问题吗?

WHat's the problem here please?

谢谢,

Jassim

推荐答案

检查
结果是否包含预期的反应。如果它是一个数组,那么试试这个:

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);

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


这篇关于HttpClient从json数据返回空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆