我使用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