在Android JSON解析中使用Web服务查看古吉拉特语字符
我有古吉拉特语这样如果古吉拉特语像અપૂર્વ比显示像第一个圆形的图像请帮助我解决这个问题
图像获取古吉拉特语像这样
代码:
public class GetProductData extends AsyncTask<String, String, JSONObject> {
//private ProgressDialog p_dialog;
JSONArray jArray;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
/*p_dialog = new ProgressDialog(con);
p_dialog.setMessage("Please Wait ...");
p_dialog.setIndeterminate(false);
p_dialog.setCancelable(false);
p_dialog.show();*/
}
@Override
protected JSONObject doInBackground(String... params) {
jArray = JSONParser.GetProductData();
Log.d("TAG", "JSON ARRAY FOR DEVICE ID : " + jArray);
String msg = "Nothing Happened...";
try {
if (jArray != null) {
Key = jArray.getJSONObject(0).getString("Key").toString();
if (Key.equals("1")) {
db.deleteAllProductDetails();
for (int i = 1; i < jArray.length(); i++) {
Log.d("ADADADADTAG","CategoryName ::: "+jArray.getJSONObject(i).getString("CategoryName"));
Log.d("ADADADADTAG","SubCategoryName ::: "+jArray.getJSONObject(i).getString("SubCategoryName").toString().trim());
Log.d("ADADADADTAG","ProductName ::: "+jArray.getJSONObject(i).getString("ProductName"));
db.insertProductDetails(
jArray.getJSONObject(i).getString("ProductId").toString().trim(),
jArray.getJSONObject(i).getString("CategoryId").toString().trim(),
jArray.getJSONObject(i).getString("CategoryName").toString().trim(),
jArray.getJSONObject(i).getString("CategoryImageUrl").toString().trim(),
jArray.getJSONObject(i).getString("SubCategoryId").toString().trim(),
jArray.getJSONObject(i).getString("SubCategoryName").toString().trim(),
jArray.getJSONObject(i).getString("SubCategoryImageUrl").toString().trim(),
jArray.getJSONObject(i).getString("ProductName").toString().trim(),
jArray.getJSONObject(i).getString("ProductImageUrl").toString().trim(),
jArray.getJSONObject(i).getString("ProductCode").toString().trim(),
jArray.getJSONObject(i).getString("ProductPrice").toString().trim(),
jArray.getJSONObject(i).getString("ProductUnit").toString().trim(),
jArray.getJSONObject(i).getString("ProductSmallDesc").toString().trim(),
jArray.getJSONObject(i).getString("CategoryStatus").toString().trim(),
jArray.getJSONObject(i).getString("SubCategoryStatus").toString().trim(),
jArray.getJSONObject(i).getString("ProductStatus").toString().trim()
);
}
}
} else {
}
} catch (Exception e) {
// TODO: handle exception
Log.e("TAG", "Warn :" + e.getLocalizedMessage());
Log.e("TAG", "Warn :" + e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(JSONObject json) {
// TODO Auto-generated method stub
super.onPostExecute(json);
// p_dialog.dismiss();
if (jArray != null) {
if (Key.equals("1")) {
Cursor cGetAllProductDetails = db.getAllProductDetails();
//Toast.makeText(con,"Count ::: "+cGetAllProductDetails.getCount(),Toast.LENGTH_LONG).show();
preferences = con.getSharedPreferences(IsLogin,Context.MODE_PRIVATE);
if(preferences.getBoolean(IsLogin,false))
{
Intent i = new Intent(con, DashboardActivityEnglishWithLogin.class);
startActivity(i);
overridePendingTransition(R.anim.left_in, R.anim.left_out);
finish();
}
else
{
Intent i = new Intent(con, DashboardActivityEnglishWithoutLogin.class);
startActivity(i);
overridePendingTransition(R.anim.left_in, R.anim.left_out);
finish();
}
} else if (Key.equals("0")) {
} else {
}
}
}
}
public static JSONArray GetProductData() {
// TODO Auto-generated method stub
try
{
init();
url = SITE_URL + "GetProductData";
Log.d("TAG", url);
httpPost = new HttpPost(url.toString());
Log.d("TAG", "HTTP POST"+httpPost);
pairs = new ArrayList<NameValuePair>();
httpPost.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
Log.d("TAG", "HTTP POST"+httpPost);
httpResponse = httpClient.execute(httpPost);
Log.d("TAG", "HTTP RESPONSE"+httpResponse);
httpEntity = httpResponse.getEntity();
inputStream = httpEntity.getContent();
/* Convert response to string */
result = getResult(inputStream);
Log.d("TAG","RESULT : "+ result);
jsonArray = new JSONArray(result);
Log.d("TAG", "JSON ARRAY : "+ jsonArray);
} catch (ClientProtocolException e) {
Log.e("TAG", "Error in Client Protocol : " + e.toString());
} catch (JSONException e) {
Log.e("TAG", "Error Parsing data " + e.toString());
} catch (Exception e) {
Log.e("TAG", "Error in HTTP Connection : " + e.toString());
}
return jsonArray;
}
使用URLDecoder解析Json数据,
URLDecoder.decode(jArray.getJSONObject(i).getString("CategoryName"), "utf-8");