android - Parse Json text as question mark -


i'm using json getting text sql database.

there many unicode formats utf-8 saving data in database.

i used utf-8 saving text. text not english. persian or arabic. json shows text ????. think problem json parser. please help.

  public class jsonparser {        static inputstream = null;       static jsonobject jobj = null;       static string json = "";        // constructor       public jsonparser() {        }        // function json url       // making http post or method       public jsonobject makehttprequest(string url, string method,           list < namevaluepair > params) {            // making http request           try {                // check request method               if (method == "post") {                   // request method post                   // defaulthttpclient                   defaulthttpclient httpclient = new defaulthttpclient();                   httppost httppost = new httppost(url);                   httppost.setentity(new urlencodedformentity(params, "utf-8"));                    httpresponse httpresponse = httpclient.execute(httppost);                   httpentity httpentity = httpresponse.getentity();                   = httpentity.getcontent();                } else if (method == "get") {                   // request method                   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();                   = 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, "utf-8"), 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 parse string json object           try {               jobj = new jsonobject(json);           } catch (jsonexception e) {               log.e("json parser", "error parsing data " + e.tostring());           }            // return json string           return jobj;        }   } 

i think problem not android. because when access php file straightly browser, shows arabic ????. i'm sure database utf-8_general_ci php below:

    <?php  // array json response $response = array();  // include db connect class define('__root__', dirname(dirname(__file__)));  require_once(__root__.'/appstore/db_connect.php');   // connecting db $db = new db_connect();  // products products table $total = mysql_query("select *from apps") or die(mysql_error()); $num_rows = mysql_num_rows($total); $result = mysql_query("select *from apps limit 0,10") or die(mysql_error());   // check empty result if (mysql_num_rows($result) > 0) { // looping through results // products node $response["products"] = array();  while ($row = mysql_fetch_array($result)) {     // temp user array     $product = array();     $product["pid"] = $row["pid"];     $product["name"] = $row["name"];     $product["rate"] = $row["rate"];     $product["short_description"] = $row["short_description"];     $product["size"] = $row["size"];     $product["thumb_url"] = $row["thumb_url"];      // push single product final response array     array_push($response["products"], $product); } // success $response["success"] = 1;  // echoing json response echo json_encode($response); } else { // no products found $response["success"] = 0; $response["message"] = "no products found";  // echo no users json echo json_encode($response); } ?> 

try use cp1256_general_ci instead of utf-8_general_ci in database.. , collation fields too.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -