[英]web request using API
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. 我正在尝试返回reddit首页上所有内容的标题。
From this site: 从此站点:
http://www.reddit.com/r/all.json http://www.reddit.com/r/all.json
I pasted the data into 我将数据粘贴到
http://json2csharp.com/# 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. 很抱歉这个问题含糊不清,但我很茫然,不知道该怎么办。
using (var webClient = new System.Net.WebClient()) {
var json = webClient.DownloadString("http://www.reddit.com/r/all.json");
}
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.