Parsing Json Feeds with google Gson

Posted by mnml on Stack Overflow See other posts from Stack Overflow or by mnml
Published on 2010-01-09T19:34:15Z Indexed on 2010/04/03 5:33 UTC
Read the original article Hit count: 533

Filed under:
|
|
|

I would like to know how to parse a json feed by items, eg. url / title / description for each item. I have had a look to the doc / api but, it didn't help me.

This is what I got so far

import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class ImportSources extends Job {
    public void doJob() throws IOException {
            String json = stringOfUrl("http://feed.test/all.json");
            JsonObject jobj = new Gson().fromJson(json, JsonObject.class);


            Logger.info(jobj.get("responseData").toString());

        }
    public static String stringOfUrl(String addr) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        URL url = new URL(addr);
        IOUtils.copy(url.openStream(), output);
        return output.toString();
    }
}   

© Stack Overflow or respective owner

Related posts about java

Related posts about JSON