JsonConvert无法反序列化整数

时间:2018-04-15 11:59:04

标签: c# xamarin cross-platform json-deserialization flask-restful

我正在尝试在Xamarin表单(跨平台)中使用python代码,所以我尝试使用flask-restful(python API)来构建Web服务器并从Xamarin应用程序调用它,我不使用数据库我只是想返回一个现在是整数,但它在Newtonsoft.Json.JsonConvert.DeserializeObject <int>(jasonstring);失败了 这就是我在xamarin中使用rest API的方式

 HttpClient client = new HttpClient();
        var response = await client.GetAsync("http://localhost:50024/");
        if (response.StatusCode == System.Net.HttpStatusCode.OK)
        {
            var jasonstring= await response.Content.ReadAsStringAsync();
             var type = Newtonsoft.Json.JsonConvert.DeserializeObject <int>(jasonstring);


            await DisplayAlert("Result", type.ToString(), "OK");
        }

这是contentstring的内容:

<!DOCTYPE html>
<html lang="en" xlmns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8"/>
  <title></title>

</head>
<body>
  <div class="info">
    <h2> 1 <br/></h2>
  </div>
</body>
</html>

以及我想要显示的整数(1)。

1 个答案:

答案 0 :(得分:1)

Newtonsoft Json .Net用于反序列化Json中表示的对象。您正在尝试使用不起作用的json反序列化器反序列化Html(xml)。我建议使用类似Html Agility Pack的东西来获取h2块中的数字

http://html-agility-pack.net/