2

I have an android application which get jSON data through HttpGet. But I am facing some problem when I show the data in the text view. The second name in the JSON data shows like my attached photo below. But when I show the jSON data in browser it shows wrong like my photo. Sorry for my poor English.

Here is my activity:

HttpClient client = new DefaultHttpClient();
            String url = "http://54.228.199.162/api/campaigns";
            try {
                String res;
                HttpGet httpget = new HttpGet(url);
                ResponseHandler<String> reshan = new BasicResponseHandler();
                res = client.execute(httpget, reshan);
                Log.d("um1", res);
                JSONArray jsonArray = new JSONArray(res);
                //campaign.setText(res);
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    String id = jsonObject.getString(TAG_ID);
                    byte[] b = id.getBytes("utf-8");
                    String utfid = new String(b);
                    String name = jsonObject.getString(TAG_NAME);
                    byte[] s = name.getBytes("utf-8");
                    String utfname = new String(s);
                    Log.d("IDDDDDDD", id);
                    Log.d("Nameeeeeee", name);
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_ID, utfid);
                    map.put(TAG_NAME, utfname);
                    //Object contactList;
                    contactList.add(map);
                  }
                HttpResponse httpresponse = client.execute(httpget);
                int responsecode = httpresponse.getStatusLine().getStatusCode();
                Log.d("responsenummmm", "um11111"+responsecode);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            };

Here is the jSON data file:

[{"_id":"520ba75acf17c8cc796b584b","name":"Oulu Liikkujan viikko 16-22.9.2013"},
{"_id":"52161d80ecaf181dc5982624","name":"Ylöjärvi Liikkujan viikko 16-22.9.2013"},
{"_id":"52262fa6d3ee051600d84c68","name":"Lapin yliopiston hyvinvointiviikko 16-22.9.2013"},
{"_id":"5293bbffbf2f15044800011d","name":"testi"},     {"_id":"52a318bbac059a0002000b4f","name":"Standing wave to Oulu"}]

Here is the problem in Text view:

In the second red line, the name

The name of the second one in the text view(photo) should be look like:Ylöjärvi Liikkujan viikko 16-22.9.2013 Please help me.

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Mohammad Rajob
  • 743
  • 1
  • 11
  • 29

3 Answers3

1

write like this Html.fromHtml(YOUR STRING)

Nitin Misra
  • 4,472
  • 3
  • 34
  • 52
0

use this to display the name..

Html.fromHtml("<font color='#ffff0000'>enter...label</font>")

Santhosh
  • 1,867
  • 2
  • 16
  • 23
0

Try to decode your your value as below :

 String decodedString = URLDecoder.decode(jsonObject.getString(TAG_ID), "UTF-8");
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • It's not working brother. The second name In text view should look like Ylöjärvi Liikkujan viikko 16-22.9.2013 as jSon data. Thank you. – Mohammad Rajob Dec 26 '13 at 05:34
  • Are you talking about the second row of your listview ? @MohammadRajob – GrIsHu Dec 26 '13 at 05:36
  • Yes brother In the second row the name should look like Ylöjärvi Liikkujan viikko 16-22.9.2013. – Mohammad Rajob Dec 26 '13 at 05:39
  • Then why don't you set the value for your second row same as your first row ? – GrIsHu Dec 26 '13 at 06:01
  • In my json data the second name is Ylöjärvi Liikkujan viikko 16-22.9.2013, but when I show it in the text view it is Ylöjärvi Liikkujan viikko 16-22.9.2013. The first part is not same as json data(Ylöjärvi). It should be Ylöjärvi. Can you understand. Thank you. – Mohammad Rajob Dec 26 '13 at 06:17
  • Well its encoding issue. May the letter does not found . – GrIsHu Dec 26 '13 at 06:24
  • Please help me brother. Yes this is encoding issue. – Mohammad Rajob Dec 26 '13 at 06:27
  • Check out this thread which might help you. http://stackoverflow.com/questions/2918920/decode-html-entities-in-android Also check this one http://stackoverflow.com/questions/4747232/non-english-characters-are-decoded-incorrectly-on-android-with-htlmcleaner @MohammadRajob – GrIsHu Dec 26 '13 at 06:32