java - JSON using loopj android listview failed -
heyy im doing movie project,i want use parsing json lisview,im using loopj library, im implement code,but not work,the listview still empty,i dont know error code, show item class first,
public class movieitem { private int id; private string title; private string description; private string rate; public movieitem(jsonobject object){ try { string title = object.getjsonarray("results").getjsonobject(0).getstring("title"); string description = object.getjsonarray("results").getjsonobject(0).getstring("overview"); double movieratet = object.getjsonarray("results").getjsonobject(0).getdouble("vote_average"); string movierate = new decimalformat("#.#").format(movieratet); this.title = title; this.description = description; this.rate = movierate; }catch (exception e){ e.printstacktrace(); } } public int getid() { return id; } public void setid(int id) { this.id = id; } public string gettitle() { return title; } public void settitle(string title) { this.title = title; } public string getdescription() { return description; } public void setdescription(string description) { this.description = description; } public string getrate() { return rate; } public void setrate(string rate) { this.rate = rate; }
}
next loader
public arraylist<movieitem> loadinbackground() { log.d("load bg","1"); synchttpclient client = new synchttpclient(); final arraylist<movieitem> movieitemses = new arraylist<>(); final string url = "https://api.themoviedb.org/3/search/movie?api_key="+api_key+"&language=en-us&query=annabelle"; client.get(url, new asynchttpresponsehandler() { @override public void onstart() { super.onstart(); setusesynchronousmode(true); } @override public void onsuccess(int statuscode, header[] headers, byte[] responsebody) { try { string result = new string(responsebody); jsonobject responseobject = new jsonobject(result); jsonarray list = responseobject.getjsonarray("list"); (int = 0 ; < list.length() ; i++){ jsonobject movie = list.getjsonobject(i); movieitem movieitems = new movieitem(movie); movieitemses.add(movieitems); } log.d("request success","1"); }catch (exception e){ e.printstacktrace(); log.d("request failed","1"); } } @override public void onfailure(int statuscode, header[] headers, byte[] responsebody, throwable error) { } }); (int = 0 ; i< movieitemses.size() ; i++){ log.d("title",movieitemses.get(i).gettitle()); } log.d("before return","1"); return movieitemses; } protected void onreleaseresources(arraylist<movieitem> data) { //nothing do. }
pls me,im fix problem,but nothing diferent
fyi im using api themoviedb
Comments
Post a Comment