-
Json textview to Json viewlist
over 7 years ago
-
over 7 years ago
First: create a model class like this:-public class MyJSONBean { /** Property ib_itemcode1 */ String ib_itemcode1; /** Property transtatuscode */ String transtatuscode; /** Property invtid */ String invtid; /** Property descr */ String descr; /** * Gets the ib_itemcode1 */ public String getIb_itemcode1() { return this.ib_itemcode1; } /** * Sets the ib_itemcode1 */ public void setIb_itemcode1(String value) { this.ib_itemcode1 = value; } /** * Gets the transtatuscode */ public String getTranstatuscode() { return this.transtatuscode; } /** * Sets the transtatuscode */ public void setTranstatuscode(String value) { this.transtatuscode = value; } /** * Gets the invtid */ public String getInvtid() { return this.invtid; } /** * Sets the invtid */ public void setInvtid(String value) { this.invtid = value; } /** * Gets the descr */ public String getDescr() { return this.descr; } /** * Sets the descr */ public void setDescr(String value) { this.descr = value; } }
Second: declare a List:-List<MyJSONBean> myList = new ArrayList<>();
Third: inside doInBackground method, put values from the JSON inside the list
Modify the for loop like this:-
for (int i = 0; i < parentArray.length(); i++) { MyJSONBean myBean = new MyJSONBean(); JSONObject finalObject = parentArray.getJSONObject(i); myBean.setIb_itemcode1(finalObject.getString("ib_itemcode1")); myBean.setTranstatuscode(finalObject.getString("transtatuscode")); myBean.setInvtid(finalObject.getString("invtid")); myBean.setDescr(finalObject.getString("descr")); myList.add(myBean); }
Fourth: inside onPostExecute method, using myList call the adapter class and set the adapter either in ListView or RecyclerView. -
1 Answer(s)