java - Parse Json Arabic text -


i can't parse arabic/persian text sql database. set utf-8. sql database text set utf8_general_ci. json parser set utf-8 too.

text shown in english. when use arabic/persian text in database, android shows text ???????.

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));              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 have been r & d around day , success parse arabic json response getting server using following code.so, may helpful you.

  httpparams params = new basichttpparams();   httpprotocolparams.setversion(params, httpversion.http_1_1);   httpprotocolparams.setcontentcharset(params, "utf-8");   params.setbooleanparameter("http.protocol.expect-continue", false);   httpclient httpclient = new defaulthttpclient(params);    httppost httppost = new httppost(your_url);   httpresponse http_response= httpclient.execute(httppost);    httpentity entity = http_response.getentity();   string jsontext = entityutils.tostring(entity, http.utf_8);    log.i("response", jsontext); 

now, use jsontext further requirement.

thank you


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 -