1

I am trying to convert the output from imbdapi, from JSON. I've been researching how to do it, but cannot seem to figure out GSON. Thanks, sorry I couldn't figure it out by myself, by no means to I mean to seem as if I was asking for spoonfeeding. If anyone could offer some help, I would be greatly appreciative.

public class Test {

    public static String getMovieInfo(String movie) {
        BufferedReader rd;
        OutputStreamWriter wr;
        //Scanner s = new Scanner(System.in);
        //System.out.println("Enter input:");
        //movie = s.nextLine();
        //movie = movie.replaceAll(" ", "%20");
        if (movie != null)
        {
            try {
                URL url = new URL("http://www.imdbapi.com/?i=&t=" + movie);
                URLConnection conn = url.openConnection();
                conn.setDoOutput(true);
                wr = new OutputStreamWriter(conn.getOutputStream());
                wr.flush();

                // Get the response
                rd = new BufferedReader(
                        new InputStreamReader(conn.getInputStream()));
                String line = rd.readLine();
                if (line != null) {
                   return line;
                } else {

                    return "Sorry! That's not a valid URL.";
                }
            } catch (UnknownHostException codeyellow) {
                System.err.println("Caught UnknownHostException: " + codeyellow.getMessage());
            }
            catch (IOException e)
            {
                System.out.println("Caught IOException:" + e.getMessage());
            }

        }
        else
        {
            return "passed parameter is null!";
        }

        return "an error occured, see console!";
    }
}
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Eric Lang
  • 274
  • 1
  • 2
  • 16

1 Answers1

0

Alright! I figured this one out myself, the documentation for Quick-JSON is a bit rough, but I figured it out. https://code.google.com/p/quick-json/ if anyone else wants it, thanks to Brandon for showing me. Thanks!

Eric Lang
  • 274
  • 1
  • 2
  • 16