I'm parsing data from web in json in gujarati language but when i receive it at android application it looks like
{"message":"Authorized","u_status":0,"c_Alert":0,"get_data":[{"id":"29","End":"2015-02-19","EntrTime":"2015-02-26","Content":"ભરતીનું સ્થળ - સાબર સ્પોર્ટ્સ સ્ટેડિયમ , હિં&","Begin":"2015-03-10","Header":"લશ્કરી ભરતી મેળો - હિંમતનગર","link":"http:\/\/www.google.com"}],"c_Alert_Msg":"No Message","u_link":"http:\/\/www.google.com","c_Alert_Finish":0,"success":1}
when i set any filtered text from json string it looks like
Ē 4;Ĕ 5;Đ 5;đ 9;
(i putted space because it shows perfect unicode in html code) but actually it is
"સ્થળ"
I know thats encoding problem but how did i convert that strings to proper unicode characters
I'm using following code for http request to get json
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_for_is);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
String result = EntityUtils.toString(httpResponse.getEntity());
JSONObject obj = new JSONObject(result);
Log.d("JSON 123123",obj.toString());
} catch (JSONException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I also tried getting string from json and converting perticular string to unicode but no effect
by this
JSONObject c = contenTs.getJSONObject(1);
String headN = c.getString("Header");
Charset chrutf = Charset.forName("UTF-8");
final String b = new String(headN.getBytes(),chrutf);
System.out.println(b);
or tell me the way that i can convert characters like 'Ē 4;Ĕ 5;Đ 5;đ 9;' to unicode string
EDIT: Maybe like this:
Or, have you tried encoding your entity using library Gson ?
You can include it like this in your build.gradle (Module: app):
and then use this part of code:
Hope it helps.
Lionel
Try this:
String jsonText = EntityUtils.toString(entity, HTTP.UTF_8);
It's really bad that my post given negative reputation because they don't know the answer but i found the solution myself
I simply converted text to html content in code and displayed it using
full code
And it worked perfectly fine