android - How to make a pojo class for this type of json data, because in this category and subcategory are combine relation is only through a id -


in json category , subcategory combine, how can arse , how set in pojo class, wan't set in expandable list view, please

 {         "product_categories": [{             "id": 24,             "name": "air cooled",             "slug": "air-cooled",             "parent": 67,             "description": "",             "display": "subcategories",             "image": "",             "count": 4         }, {             "id": 33,             "name": "belt driven",             "slug": "bet-driven",             "parent": 25,             "description": "",             "display": "default",             "image": "",             "count": 15         }, {             "id": 25,             "name": "cnc lathe spindle",             "slug": "cnclathespindle",             "parent": 0,             "description": "",             "display": "default",             "image": "",             "count": 15         }, {             "id": 28,             "name": "cnc milling spindle",             "slug": "cncmillingspindle",             "parent": 0,             "description": "",             "display": "default",             "image": "",             "count": 9         }, {             "id": 29,             "name": "motorised",             "slug": "singles",             "parent": 25,             "description": "",             "display": "default",             "image": "",             "count": 0         }, {             "id": 21,             "name": "motorized spindle",             "slug": "motorizedspindle",             "parent": 0,             "description": "",             "display": "default",             "image": "",             "count": 11         }, {             "id": 30,             "name": "water cooled",             "slug": "water-cooled",             "parent": 67,             "description": "",             "display": "subcategories",             "image": "",             "count": 7         }, {             "id": 67,             "name": "wood acrylic engraving",             "slug": "wood-acrylic-engraving",             "parent": 21,             "description": "",             "display": "products",             "image": "",             "count": 0         }]     } 

in json category , subcategory combine, how can arse , how set in pojo class, wan't set in expandable list view, please help

you have parse json response , store different categories in different arraylist , based on user selection of render position can use selected arraylist.

you can parsing json response this

jsonobject jsonobject = new jsonobject(response); // response json string gettting server      jsonarray jsonarray = jsonobject.getjsonobject("product_categories");      arraylist<categorydisplay> catdislist = new arraylist<>();     arraylist<defaultdisplay> defaultdislist = new arraylist<>();      (int = 0; < jsonarray.length(); i++) {         jsonobject jsonobject = jsonarray.getjsonobject(i);         somemodel somemodel = new somemodel();         if (jsonobject.has("id")) {             somemodel.setid(jsonobject.getstring("id"));         }         if (jsonobject.has("name")) {             somemodel.setname(jsonobject.getstring("name"));         }          on.....          if(somemodel.getdisplay().equals("default")){             defaultdislist.add(somemodel);         }else{             catdislist.add(somemodel);         }      } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -