java - How to format a long json text from Wordpress in Android -
i have asked question before, did not helpful answer.
i long json text in android app wordpress , want format have paragraph. text has bullets 1,2,3, - need text display in below format:
1........
2.......
3.......
this how getting in json:
public class didyouknow extends sherlocklistactivity { private actionbarmenu abm; private progressdialog pdialog; // url contacts json private static string url = ""; // json node names private static final string tag_query = "posts"; private static final string tag_id = "id"; private static final string tag_title = "title"; private static final string tag_content = "content"; // contacts jsonarray jsonarray query = null; // hashmap listview arraylist<hashmap<string, string>> querylist; @suppresswarnings("deprecation") @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_upcoming); actionbar actionbar = getsupportactionbar(); actionbar.setdisplayhomeasupenabled(true); abm = new actionbarmenu(didyouknow.this); if (com.cepfmobileapp.org.service.internetstatus.getinstance(this).isonline(this)) { // toast t = toast.maketext(this,"you online!!!!",8000).show(); // toast.maketext(getbasecontext(),"you online",toast.length_short).show(); // calling async task json new getquery().execute(); } else { alertdialog netalert = new alertdialog.builder(didyouknow.this).create(); netalert.setmessage("no internet connection found!"); netalert.setbutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { } }); netalert.show(); } querylist = new arraylist<hashmap<string, string>>(); listview lv = getlistview(); // listview on item click listener lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // getting values selected listitem // starting single contact activity /*intent in = new intent(getapplicationcontext(),singlecontactactivity.class); in.putextra(tag_name, name); in.putextra(tag_email, cost); in.putextra(tag_phone_mobile, description); startactivity(in);*/ } }); } private string parsehtml(string html){ document doc = jsoup.parse(html); return doc.text(); } private class getquery extends asynctask<void, void, void> { @override protected void onpreexecute() { super.onpreexecute(); // showing progress dialog pdialog = new progressdialog(didyouknow.this); pdialog.setmessage("loading..."); pdialog.setcancelable(false); pdialog.show(); } @override protected void doinbackground(void... arg0) { // creating service handler class instance servicehandler sh = new servicehandler(); // making request url , getting response string jsonstr = sh.makeservicecall(url, servicehandler.get); log.d("response: ", "> " + jsonstr); if (jsonstr != null) { try { jsonobject jsonobj = new jsonobject(jsonstr); // getting json array node query = jsonobj.getjsonarray(tag_query); // looping through contacts (int = 0; < query.length(); i++) { jsonobject c = query.getjsonobject(i); string id = c.getstring(tag_id); string title = c.getstring(tag_title); string content = c.getstring(tag_content); //string address = c.getstring(tag_address); //string gender = c.getstring(tag_gender); // tmp hashmap single contact hashmap<string, string> contact = new hashmap<string, string>(); // adding each child node hashmap key => value contact.put(tag_id, id); contact.put(tag_title, title); contact.put(tag_content, parsehtml(content)); //contact.put(tag_phone_mobile, mobile); // adding contact contact list querylist.add(contact); } } catch (jsonexception e) { e.printstacktrace(); } } else { log.e("servicehandler", "couldn't data url"); } return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); // dismiss progress dialog if (pdialog.isshowing()) pdialog.dismiss();
as json looking @ in hmtl can display in html page.
if want parse string using java here rough sketch of how can it:
update: code:
jsonobject c = query.getjsonobject(i); string id = c.getstring(tag_id); string title = c.getstring(tag_title); string content = c.getstring(tag_content);
the string content holds content string jsonobject.
string[] split = content.split("<p>2");
now have array of strings,
split1[0] = "<p>1)...." split1[1] = ")content of p2 , p3 , forth..."
so need substring [0] remove "<p>1"
paragraph1 = split[0].substring(3);
then have split split[1] paragraph 2 , rest
string[] split2 = split[1].split("<p>3"); string paragraph2 = split2[0];
keep doing paragraphs need. easier if print out each string after every split, better grip of whats going on.
Comments
Post a Comment