I was working on yahoo news feed data and i want my output in JSON format. here i am using "rss news feed api" to get the yahoo news data. So by default the output of RSS feed will be in XML format, but i want the output in JSON format.
here is the code which I am working on.
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();
} }
I have also added format=json in the url to get the output as JSON. But I didn't get succeed by doing that.
http://news.yahoo.com/rss/us?format=json
I have tried many ways which in turn caused failure. Can anyone help me out for getting the JSON output.