加载JSON错误

时间:2016-04-13 12:19:28

标签: c# json win-universal-app

我尝试像这样加载json

private async Task<JsonValue> FetchAsync(string url)
{
    // Create an HTTP web request using the URL:
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
    request.ContentType = "application/json";
    request.Method = "GET";

    // Send the request to the server and wait for the response:
    using (WebResponse response = await request.GetResponseAsync())
    {
        // Get a stream representation of the HTTP web response:
        using (Stream stream = response.GetResponseStream())
        {
            // Use this stream to build a JSON document object:
            JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));

            Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());

            // Return the JSON document:
            return jsonDoc;
        }
    }
}

但在此JsonObject.Load(stream));我有错误:

  

错误CS0117&#39; JsonObject&#39;不包含&#39;加载&#39;

的定义

正如我在MSDN上读到的那样,JsonObject有Load方法。

我的代码有什么问题?

1 个答案:

答案 0 :(得分:0)

我知道这篇文章已经晚了但也许我可以帮助其他人。 您应该将此行添加到项目中:

using System.Json

右键单击引用,然后单击“添加引用”。检查System.Json框,然后单击“确定”。