我开发了一个应用程序,在文本视图中显示印地文和其他印度语言功能,并使用json url从php mysql服务器获取数据,但问题是当我得到数据英文显示完美但我在印地文获取数据时其他语言显示如下?????? ????? ???? ???? ?????
。
什么是背后的故障以及哪一方是php方面还是android方面?
主要活动代码:
public class JSONUseActivity extends Activity {
String returnString;
private TextView about;
private ImageView image;
String image_url;
@Override
public void onCreate(Bundle savedInstanceState) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jsonuse);
about=(TextView)findViewById(R.id.tv);
Typeface tf=Typeface.createFromAsset(JSONUseActivity.this.getAssets(),"Shruti.ttf");
about.setTypeface(tf);
image=(ImageView)findViewById(R.id.iv);
url_through_image.ImageLoader imgloader=new url_through_image.ImageLoader(getApplicationContext());
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
int loader = R.drawable.loader;
postParameters.add(new BasicNameValuePair("temple_id",
"2"));
String response = null;
try {
response = CustomHttpClient.executeHttpPost(
"url", // in case of a remote server
postParameters);
String result = response.toString();
try{
returnString = "";
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++)
{
JSONObject json_data = jArray.getJSONObject(i);
returnString=json_data.getString("about_text");
image_url="url";
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
try{
about.setText(returnString);
imgloader.DisplayImage(image_url, loader,image);
}
catch(Exception e){
Log.e("log_tag","Error in Display!" + e.toString());;
}
}
catch (Exception e) {
Log.e("log_tag","Error in http connection!!" + e.toString());
}
}
}
json parser is here..
private static HttpClient getHttpClient() {
if (mHttpClient == null) {
mHttpClient = new DefaultHttpClient();
final HttpParams params = mHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
}
return mHttpClient;
}
public static String executeHttpPost(String url,ArrayList<NameValuePair> postParameters) throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpPost request = new HttpPost(url);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
postParameters,"UTF-8");
request.setEntity(formEntity);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent() ,"UTF-8"));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String result = sb.toString();
return result;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
Log.e("log_tag", "Error converting result "+e.toString());
e.printStackTrace();
}
}
}
}
public static String executeHttpGet(String url) throws Exception {
BufferedReader in = null;
try {
HttpClient client = getHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent(),"UTF-8"));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String result = sb.toString();
return result;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
Log.e("log_tag", "Error converting result "+e.toString());
e.printStackTrace();
}
}
}