【发布时间】:2016-06-08 12:13:02
【问题描述】:
我正在处理 yahoo 新闻提要数据,我想要 JSON 格式的输出。这里我使用“rss news feed api”来获取雅虎新闻数据。所以默认情况下,RSS 提要的输出将是 XML 格式,但我想要 JSON 格式的输出。
这是我正在处理的代码。
import java.net.URL;
import java.io.*;
import javax.net.ssl.HttpsURLConnection;
//import java.net.HttpURLConnection;
public class JavaHttpsExample {
public static void main(String[] args) throws Exception {
String httpsURL = "http://news.yahoo.com/rss/us";
URL myurl = new URL(null, httpsURL, new sun.net.www.protocol.https.Handler());
HttpsURLConnection con = (HttpsURLConnection) myurl.openConnection();
InputStream ins = con.getInputStream();
InputStreamReader isr = new InputStreamReader(ins);
BufferedReader in = new BufferedReader(isr);
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} }
我还在 url 中添加了 format=json 以获取 JSON 格式的输出。但我这样做并没有成功。
http://news.yahoo.com/rss/us?format=json
我尝试了很多方法,最终导致失败。谁能帮我获取 JSON 输出。
【问题讨论】: