title: Converting String to Android JSONObject loses utf-8
body: <p>I am trying to get a (JSON formatted) String from a URL and consume it as a Json object. I lose UTF-8 encoding when I convert the String to JSONObject.</p>
  
  <p>This is The function I use to connect to the url and get the string:</p>
  
  <pre><code>private static String getUrlContents(String theUrl) {
      StringBuilder content = new StringBuilder();
      try {
          URL url = new URL(theUrl);
          URLConnection urlConnection = url.openConnection();
          BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
  
          String line;
          while ((line = bufferedReader.readLine()) != null) {
              content.append(line + "\n");
          }
          bufferedReader.close();
      } catch(Exception e) {
          e.printStackTrace();
      }
  
      return content.toString();
  }
  </code></pre>
  
  <p>When I get data from server, the following code displays correct characters:</p>
  
  <pre><code>String output = getUrlContents(url);
  Log.i("message1", output);
  </code></pre>
  
  <p>But when I convert the output string to JSONObject the Persian characters becomes question marks like this ??????. (messages is the name of array in JSON)</p>
  
  <pre><code>JSONObject reader = new JSONObject(output);
  String messages = new String(reader.getString("messages").getBytes("ISO-8859-1"), "UTF-8");
  Log.i("message2", messages);
  </code></pre>