I am developing Windows store app in Windows 8, Visual Studio 2012. I need to make GET request to a particular URL and get the JSON as response. And I need to parse the JSON to get the values in it. I need C# code to do the above functionality.
问问题
32108 次
2 回答
11
你可以使用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));
}
于 2013-03-05T09:12:53.760 回答
1
您可以使用MSDN中的此示例代码
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);
于 2013-03-05T09:18:15.570 回答