I am trying to write JAVA code to get answers from Google. The code I write only works fine in English, but when I try to add some Hebrew characters, the answers I get are different than when I write it on the Google website.
Here is the code:
String address = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="; String charset = "UTF-8"; URL url; try { url = new URL(address + URLEncoder.encode(artistAndSong + site, charset)); //The url seems right, and it the same as the url that appear on the web Reader reader = new InputStreamReader(url.openStream(), charset); GoogleResults results = new Gson().fromJson(reader, GoogleResults.class); res =(results.getResponseData().getResults().get(0).getUrl()); //This is the part where I see that the answers are not the same } class GoogleResults{ private ResponseData responseData; public ResponseData getResponseData() { return responseData; } public void setResponseData(ResponseData responseData) { this.responseData = responseData; } public String toString() { return "ResponseData[" + responseData + "]"; } static class ResponseData { private List<Result> results; public List<Result> getResults() { return results; } public void setResults(List<Result> results) { this.results = results; } public String toString() { return "Results[" + results + "]"; } } static class Result { private String url; private String title; public String getUrl() { return url; } public String getTitle() { return title; } public void setUrl(String url) { this.url = url; } public void setTitle(String title) { this.title = title; } public String toString() { return "Result[url:" + url +",title:" + title + "]"; } } }
Does anyone have an Idea? I’ve been trying to solve this for a couple of days ... (Also, I tried to play with Unicode, but it didn't seem to solve it.)
Thanks!
source share