title: Android - using json to pass non english characters,and getting it as question marks(???) to and from the server
body: <p>What I'm trying to do is using json parser class in order to pass string to and from an sql database.</p>
  
  <p>In order to do so, I'm using the next JsonParser class code to pass and get the strings value from and to the sql database -</p>
  
  <pre><code>public class JSONParser {
  
  static InputStream is = null;
  static JSONObject jObj = null;
  static String json = "";
  
  
  public JSONParser() {
  
  }
  
  
  public JSONObject getJSONFromUrl(final String url) {
  
  
      try {
  
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(url);
  
  
          HttpResponse httpResponse = httpClient.execute(httpPost);
  
          HttpEntity httpEntity = httpResponse.getEntity();
  
          is = httpEntity.getContent();
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      try {
  
          BufferedReader reader = new BufferedReader(new InputStreamReader(
                  is, "iso-8859-1"), 8);
  
          StringBuilder sb = new StringBuilder();
  
          String line = null;
  
  
          while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
          }
  
  
          is.close();
  
          json = sb.toString();
      } catch (Exception e) {
          Log.e("Buffer Error", "Error converting result " + e.toString());
      }
  
  
      try {
          jObj = new JSONObject(json);
      } catch (JSONException e) {
          Log.e("JSON Parser", "Error parsing data " + e.toString());
      }
  
  
      return jObj;
  
  }
  
  
  // function get json from url
  // by making HTTP POST or GET mehtod
  public JSONObject makeHttpRequest(String url, String method,
          List&lt;NameValuePair&gt; params) {
  
  
      try {
  
  
          if(method == "POST"){
  
              DefaultHttpClient httpClient = new DefaultHttpClient();
              HttpPost httpPost = new HttpPost(url);
              httpPost.setEntity(new UrlEncodedFormEntity(params));
  
              HttpResponse httpResponse = httpClient.execute(httpPost);
              HttpEntity httpEntity = httpResponse.getEntity();
              is = httpEntity.getContent();
  
          }else if(method == "GET"){
  
              DefaultHttpClient httpClient = new DefaultHttpClient();
              String paramString = URLEncodedUtils.format(params, "utf-8");
              url += "?" + paramString;
              HttpGet httpGet = new HttpGet(url);
  
              HttpResponse httpResponse = httpClient.execute(httpGet);
              HttpEntity httpEntity = httpResponse.getEntity();
              is = httpEntity.getContent();
          }           
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      try {
          BufferedReader reader = new BufferedReader(new InputStreamReader(
                  is, "iso-8859-1"), 8);
          StringBuilder sb = new StringBuilder();
          String line = null;
          while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
          }
          is.close();
          json = sb.toString();
      } catch (Exception e) {
          Log.e("Buffer Error", "Error converting result " + e.toString());
      }
  
  
      try {
          jObj = new JSONObject(json);
      } catch (JSONException e) {
          Log.e("JSON Parser", "Error parsing data " + e.toString());
      }
  
  
      return jObj;
  
  }
  }
  </code></pre>
  
  <p>Now it's working fine when it need to handle an english letters, but when I'm trying to pass a non english letters then it turns into question marks.</p>
  
  <p>I can see the question marks at the Sql DB and also when I'm using the class to read results from the Sql I'm getting those question marks as results.</p>
  
  <p>So I'm guessing that I'm missing something at JasonParser class when it sends data to the Sql.</p>
  
  <p>Just to be sure that all other components are fine I'm adding codes that are involve in the sending info from the app to the server.</p>
  
  <p>The next code is php for getting access to the DB -</p>
  
  <pre><code>  $username = "xxxxx"; 
  $password = "xxxxx"; 
  $host = "xxxxx"; 
  $dbname = "xxxxxx"; 
  
  
  
  $options = array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; 'SET NAMES utf8'); 
  
  
  try 
  { 
  
      $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); 
  } 
  catch(PDOException $ex) 
  { 
  
      die("Failed to connect to the database: " . $ex-&gt;getMessage()); 
  } 
  
  $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
  
  
  $db-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); 
  
  
  if(function_exists('get_magic_quotes_gpc') &amp;&amp; get_magic_quotes_gpc()) 
  { 
      function undo_magic_quotes_gpc(&amp;$array) 
      { 
          foreach($array as &amp;$value) 
          { 
              if(is_array($value)) 
              { 
                  undo_magic_quotes_gpc($value); 
              } 
              else 
              { 
                  $value = stripslashes($value); 
              } 
          } 
      } 
  
      undo_magic_quotes_gpc($_POST); 
      undo_magic_quotes_gpc($_GET); 
      undo_magic_quotes_gpc($_COOKIE); 
  } 
  
  
  header('Content-Type: text/html; charset=utf-8'); 
  
  
  session_start(); 
  </code></pre>
  
  <p>The next code is how I set the Sql table -</p>
  
  <pre><code>      CREATE TABLE IF NOT EXISTS `users` (
    `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `username` varchar(45) NOT NULL DEFAULT '',
    `password` varchar(32) NOT NULL DEFAULT '',
    PRIMARY KEY (`Id`),
    UNIQUE KEY `Index_2` (`username`),
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  </code></pre>
  
  <p>As you can see I'm using in both codes the - utf8  - encoding - so that's why I'm thinking that something is missing at my JsonParser class in order to get it work fine.</p>
  
  <p>So what am I missing here?</p>
  
  <p>Thanks for any kind of help</p>