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,58528 gold badges42 silver badges51 bronze badges
asked Dec 26, 2013 at 5:09
3
  • You question is not clear. Commented Dec 26, 2013 at 5:13
  • you a custom Font for your TextView. Commented Dec 26, 2013 at 5:13
  • Check out my answer and try out. Commented Dec 26, 2013 at 5:26

3 Answers 3

1

write like this Html.fromHtml(YOUR STRING)

answered Dec 26, 2013 at 5:13
Sign up to request clarification or add additional context in comments.

1 Comment

None of the answers found worked, until found this. Marvelous!
0

Try to decode your your value as below :

 String decodedString = URLDecoder.decode(jsonObject.getString(TAG_ID), "UTF-8");
answered Dec 26, 2013 at 5:14

8 Comments

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.
Are you talking about the second row of your listview ? @MohammadRajob
Yes brother In the second row the name should look like Ylöjärvi Liikkujan viikko 16-22.9.2013.
Then why don't you set the value for your second row same as your first row ?
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.
|
0

use this to display the name..

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

answered Dec 26, 2013 at 5:14

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.