将Json结果转换为Java对象

时间:2017-06-25 13:48:45

标签: java

我想将我的谷歌搜索链接打印到控制台。 为此,我试图将JSON转换为Java对象。 但我得到了以下结果:

  

de.google.search.GoogleSearchJava@31ea9581

看看我的代码:

 ...

    URL url = new URL("https://www.googleapis.com/customsearch/v1?key="+key+ "&cx="+ cx +"&q="+ search +"&alt=json&num=1");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            System.out.println("Connection opened!");
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");
            BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

            GoogleSearchJava data = new Gson().fromJson(br, GoogleSearchJava.class);


            // Show it.
            System.out.println(data);

            conn.disconnect();           
  ...

0 个答案:

没有答案