小编Ala*_*ala的帖子

将任务<字符串> 转换为字符串

我想从通用 Windows Phone 应用程序中的 JSON 文件进行解析,但我无法将任务转换为字符串

public MainPage()
    {
        this.InitializeComponent();

        HttpClient httpClient = new HttpClient();
        String responseLine;
        JObject o;
        try
        {
            string responseBodyAsText;

            HttpResponseMessage response = httpClient.GetAsync("http://localhost/list.php").Result;

            //response = await client.PostAsync(url, new FormUrlEncodedContent(values));
            response.EnsureSuccessStatusCode();
            responseBodyAsText = response.Content.ReadAsStringAsync().Result;
           // responseLine = responseBodyAsText;
              string Website = "http://localhost/list.php";
            Task<string> datatask =  httpClient.GetStringAsync(new Uri(string.Format(Website, DateTime.UtcNow.Ticks)));
            string data = await datatask;
            o = JObject.Parse(data);
            Debug.WriteLine("firstname:" + o["id"][0]);
        }
        catch (HttpRequestException hre)
        {
        }
Run Code Online (Sandbox Code Playgroud)

我在这一行有错误

 string data = await datatask;
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

c# async-await win-universal-app

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

async-await ×1

c# ×1

win-universal-app ×1