Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First try this:</p> <pre><code>str = j.getString("titleNoFormatting"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("c:/test.txt"), "UTF-8")); writer.write(str); writer.close(); </code></pre> <p>Then open the file in notepad. If this looks fine, then the problem lies in your logger or console that it's not configured to use <code>UTF-8</code>. Else the problem most likely lies in the JSON API which you used that it's not configured to use <code>UTF-8</code>.</p> <p><strong>Edit</strong>: if the problem is actually in the JSON API used and you don't know which to choose, then I'd recommend to use <a href="http://code.google.com/p/google-gson/" rel="nofollow noreferrer">Gson</a>. It really eases converting a Json string to a easy-to-use javabean. Here's a basic example:</p> <pre><code>import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.util.List; import com.google.gson.Gson; public class Test { public static void main(String[] args) throws Exception { URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web" + "?start=0&amp;rsz=large&amp;v=1.0&amp;q=rz+img+news+recordid+border"); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); GoogleResults results = new Gson().fromJson(reader, GoogleResults.class); // Show all results. System.out.println(results); // Show title of 1st result (is arabic). System.out.println(results.getResponseData().getResults().get(0).getTitle()); } } class GoogleResults { ResponseData responseData; public ResponseData getResponseData() { return responseData; } public void setResponseData(ResponseData responseData) { this.responseData = responseData; } public String toString() { return "ResponseData[" + responseData + "]"; } static class ResponseData { List&lt;Result&gt; results; public List&lt;Result&gt; getResults() { return results; } public void setResults(List&lt;Result&gt; 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 + "]"; } } } </code></pre> <p>It outputs the results nicely. Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload