0
我一直在玩GSON和JSON來完成搜索並顯示結果。我有這樣的一段代碼,但我不能讓它顯示結果:顯示搜索結果
public static void main(String args[]) throws IOException
{
String google = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=";
String search = "food pantries in Dallas";
String charset = "UTF-8";
URL url = new URL(google + URLEncoder.encode(search, charset));
Reader reader = new InputStreamReader(url.openStream());
GoogleResults results = new Gson().fromJson(reader, GoogleResults.class);
// Show title and URL of 1st result.
System.out.println(results.getResponseData().getResults().get(0).getTitle());
System.out.println(results.getResponseData().getResults().get(0).getUrl());
System.out.println(results.getResponseData().getResults());
}
UPDATE:
我能夠使用搜索,獲得了一定的成果,它是顯示的列表如下:
<b>Food Pantries</b> | Soup Kitchens | <b>Food Banks</b>
http://www.foodpantries.org/
[Result[url:http://www.foodpantries.org/,title:<b>Food Pantries</b> | Soup Kitchens | <b>Food Banks</b>], Result[url:http://feedingamerica.org/foodbank-results.aspx,title:Find a Local <b>Food Bank</b> | Feeding America], Result[url:http://www.foodbanknyc.org/,title:<b>Food Bank</b> for New York City], Result[url:http://en.wikipedia.org/wiki/Food_bank,title:<b>Food bank</b> - Wikipedia, the free encyclopedia]]
我想創建一個乾淨的列表,將顯示這個結果只顯示網站,也許一些更多的信息。
我正在考慮使用Jsoup,但不知道如何整合這兩個。有什麼建議?
謝謝,
理查德。
感謝您的回答。我改變了代碼,我得到了一些答案。我已經更新了上面的代碼。現在我得到了一些結果,我需要格式化結果以顯示一個不錯的列表。我會在下面發佈代碼和答案。 – Richard