我正在开发Windows 8中的Windows商店应用程序,使用Visual Studio 2012。我需要向特定URL发出GET请求,并获取JSON作为响应。我需要解析JSON以获取其中的值。我需要C#代码来执行上述功能。
HttpClient
类。GetAsync方法允许您向指定的url发送GET请求:public async Task<JsonObject> GetAsync(string uri)
{
var httpClient = new HttpClient();
var content = await httpClient.GetStringAsync(uri);
return await Task.Run(() => JsonObject.Parse(content));
}
var client = new HttpClient();
var uri = new Uri("http://ponify.me/stats.php");
Stream respStream = await client.GetStreamAsync(uri);
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(rootObject));
rootObject feed = (rootObject)ser.ReadObject(respStream);
System.Diagnostics.Debug.WriteLine(feed.SONGHISTORY[0].TITLE);
JsonValue
而不是JsonObject
。 - Simple