i'm trying pull set of json arrays remote url, reason keep getting force closed. kind of can on appreciated!
my remote json url outputs:
[ { "title": "name1", "url": "http:\/\/radio.shoutcast.com\/fm", "location": "usa", "webtitle": "\u0111i kh\u00f4ng em y\u1ec7u?", "weburl": "http:\/\/www.cnn.com" }, { "title": "msnbc", "url": "http:\/\/radio.cnn.com\/cnn", "location": "usa", "webtitle": "kh\u00f4ng \u0111i \u0111\u00e2u", "weburl": "http:\/\/www.espn.com" } ] so in java code, have this:
public void createradiolistforradioscreen(tablelayout uiradiolist, arraylist<string> userradios, textview radiolistname, textview radiolistlocation) { arraylist<radiolistelement> radioarray = new arraylist<radiolistelement>(); mainactivity.getdatamanager().loadstoredradiostations(radioarray, userradios); radioarray.add(new radiolistelement(context, "106.3 fm", "www.cnn.com", "http://radio.cnn.com/cnn")); uiradiolist.removeallviews(); radiolist radiolist = new radiolist(context, radioarray, uiradiolist); radiolist.addradiostations(radiolistname, radiolistlocation); } i want load necessary fields current array. declare on mainactivity.java
string tag_title = "title"; string tag_url = "url"; string tag_location = "location"; string tag_webtitle = "webtitle"; string tag_weburl = "weburl"; string title, url, location, webtitle, weburl; public arraylist<hashmap<string, string>> radlist = new arraylist<hashmap<string, string>>();; code pull json
protected void doinbackground(void... arg0) { try { jsonarray json = jsonparser.getjsonfromurl(getresources() .getstring(r.string.url)); log.e("mainactivitty", json.tostring()); (int = 0; < json.length(); i++) { jsonobject c = json.getjsonobject(i); title = c.getstring(tag_title); url = c.getstring(tag_url); location = c.getstring(tag_location); webtitle = c.getstring(tag_webtitle); weburl = c.getstring(tag_weburl); hashmap<string, string> map = new hashmap<string, string>(); // adding each child node hashmap key => value map.put(tag_title, title); map.put(tag_url, url); map.put(tag_location, location); map.put(tag_webtitle, webtitle); map.put(tag_weburl, weburl); // adding hashlist arraylist radlist.add(map); } } catch (exception e) { e.printstacktrace(); } return null; } } please me bring url code, thank much!
update code this
for (int =0; a<radlist.size();a++) { hashmap<string, string> tmpdata = (hashmap<string, string>) radlist.get(a); set<string> key = tmpdata.keyset(); iterator = key.iterator(); string title; string url; string location; string webtitle; string weburl; while (it.hasnext()) { title = tmpdata.get(tag_title); url = tmpdata.get(tag_url); location = tmpdata.get(tag_location); webtitle= tmpdata.get(tag_webtitle); weburl = tmpdata.get(tag_weburl); it.remove(); } radioarray.add(new radiolistelement(context, webtitle, url , weburl)); } i didnt test code should give idea solved problem.
Comments
Post a Comment