0

I have done something similar to this before however I'm not sure how to do this with a bigger project. I'm trying to return the titles of all the stuff on the front page of reddit.

From this site:

http://www.reddit.com/r/all.json

I pasted the data into

http://json2csharp.com/#

to find out the class I need.

From here though, I'm not too sure on how to proceed. If I wanted to return an array of all this data so I can easily get information, how could I do it. Sorry for the vagueness of this question but I'm just at a loss and don't know what to do.

1 Answer 1

0

Use

using (var webClient = new System.Net.WebClient()) {
    var json = webClient.DownloadString("http://www.reddit.com/r/all.json");
}

For old .Net:

var request = WebRequest.Create(url);
string text;
 request.ContentType = "application/json; charset=utf-8";

var response = (HttpWebResponse) request.GetResponse();

using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}
Sign up to request clarification or add additional context in comments.

7 Comments

I get an error on the new System.Net.WebClient, says that it doesn't exist in the namespace and I can't import it.
In System.Net.WebClient
@AndyOHart What is you .net vesrion
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.