-1

View Gujarati Character Using Web Service in Android JSON Parsing

I Got Gujarati Word Like the one in the images I've included. If Gujarati Word is presented like અપૂર્વ, then it appears like the 1st rounded circle in the image.

Please help me to find a solution to this question

Image For Getting Gujarati Word Like this can be seen below:

enter image description here

And here is my code :

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").trim());
                        Log.d("ADADADADTAG","ProductName ::: "+jArray.getJSONObject(i).getString("ProductName"));

                        db.insertProductDetails(
                                jArray.getJSONObject(i).getString("ProductId").trim(),
                                jArray.getJSONObject(i).getString("CategoryId").trim(),
                                jArray.getJSONObject(i).getString("CategoryName").trim(),
                                jArray.getJSONObject(i).getString("CategoryImageUrl").trim(),
                                jArray.getJSONObject(i).getString("SubCategoryId").trim(),
                                jArray.getJSONObject(i).getString("SubCategoryName").trim(),
                                jArray.getJSONObject(i).getString("SubCategoryImageUrl").trim(),
                                jArray.getJSONObject(i).getString("ProductName").trim(),
                                jArray.getJSONObject(i).getString("ProductImageUrl").trim(),
                                jArray.getJSONObject(i).getString("ProductCode").trim(),
                                jArray.getJSONObject(i).getString("ProductPrice").trim(),
                                jArray.getJSONObject(i).getString("ProductUnit").trim(),
                                jArray.getJSONObject(i).getString("ProductSmallDesc").trim(),
                                jArray.getJSONObject(i).getString("CategoryStatus").trim(),
                                jArray.getJSONObject(i).getString("SubCategoryStatus").trim(),
                                jArray.getJSONObject(i).getString("ProductStatus").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;
}
Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
APOORVA DOSHI
  • 61
  • 1
  • 3

2 Answers2

0

Parse Json data using URLDecoder,

URLDecoder.decode(jArray.getJSONObject(i).getString("CategoryName"), "utf-8");
Bhavya Gandhi
  • 507
  • 3
  • 10
0

Try this

StringRequest stringRequest = new StringRequest(Request.Method.GET,"http://floming.com/shayri/guj_romanse.json", new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        String str = "";
        try {
            str = new String(response.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {

            e.printStackTrace();
        }

        String decodedStr = Html.fromHtml(str).toString();
Daxesh V
  • 571
  • 6
  • 12