【发布时间】:2018-09-25 06:26:37
【问题描述】:
我正在尝试在 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)。
【问题讨论】:
-
您应该检查您的 API。当您发送请求时,它应该是返回部分资源。您的 API 响应似乎不可用。
-
所以你试图将 XML 反序列化为 JSON,以某种方式假装整个事情是一个整数?然后你真的想知道可能出了什么问题?
-
这是我的第一个 rest api 我不知道如何返回整数
标签: c# xamarin cross-platform json-deserialization flask-restful