我使用Xamarin形式,我试图获得设在这里的文件的JSON字符串。不过,我似乎无法获得Json字符串。这是我的代码:获取JSON字符串的HttpClient
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' 转换
您是否收到错误?你没有想到的东西?或者什么也没有? – Tim 2014-10-01 05:11:37
它不会因为该行任务T =新任务(的getJSON(“https://dl.dropboxusercontent.com/u/37802978/policyHolder.json”))的编译; – Kuzon 2014-10-01 05:14:28
我编辑了你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2014-10-01 05:30:56