C # GET Request and JSON Analysis

I am developing a Windows storage application on Windows 8, Visual Studio 2012. I need to make a GET request to a specific URL and get JSON as the response. And I need to parse JSON to get the values ​​in it. I need C # code to perform the above functions.

+5
source share
2 answers

You can use this sample code from 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);
+1
source

You can use a class HttpClient. The GetAsync method allows you to send a GET request to the specified URL:

public async Task<JsonObject> GetAsync(string uri)
{
    var httpClient = new HttpClient();
    var content = await httpClient.GetStringAsync(uri);
    return await Task.Run(() => JsonObject.Parse(content));
}
+7
source

All Articles