【发布时间】:2014-10-01 05:02:12
【问题描述】:
我正在使用 Xamarin Forms,我正在尝试获取位于此处的文件的 JSON 字符串。但是我似乎无法取出 Json 字符串。这是我的代码:
public async static Task<string> GetJson(string URL)
{
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(URL))
using (HttpContent content = response.Content)
{
// ... Read the string.
return await content.ReadAsStringAsync();
}
}
private static void FindJsonString()
{
Task t = new Task(GetJson("https://dl.dropboxusercontent.com/u/37802978/policyHolder.json"));
t.Start();
t.Wait();
string Json = t.ToString();
}
我做错了什么?
我得到与这条线有关的这 2 个错误
Task t = new Task(GetJson("https://dl.dropboxusercontent.com/u/37802978/policyHolder.json"));
错误 1
'System.Threading.Tasks.Task.Task(System.Action)' 的最佳重载方法匹配有一些无效参数错误 2
参数 1:无法从 'System.Threading.Tasks.Task' 转换为 'System.Action'
【问题讨论】:
-
您遇到错误了吗?你没想到的东西回来了?还是什么都没有?
-
因为这条线所以无法编译 Task t = new Task(GetJson("dl.dropboxusercontent.com/u/37802978/policyHolder.json"));
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
标签: c# .net json async-await httpclient