android - Combine json and make arraylist<object> -
i have json want combine data 1st object 2nd object
{ "viewid": { "56": { "viewid": "56", "name": "hi", "param": "value" }, "88": { "viewid": "88", "name": "hi2", "param": "value2" } }, "que": [ { "rid": "123", "viewid": "88", "count": 0 }, { "rid": "456", "viewid": "56", "count": 0 } ] }
basically making arraylist, how can add viewid data in que. want merge json in following way:
{ "que": [ { "rid": "123", "viewid": "88", "name": "hi2", "param": "value2", "count": 0 }, { "rid": "456", "viewid": "56", "name": "hi", "param": "value", "count": 0 } ] }
jsonobject viewidjsnobject = new jsonobject(); //replace new jsonobject() viewid json object here jsonarray quearray = new jsonarray();//replace new jsonarray() actual json array; //traverse through que objects in array if(quearray != null && quearray.length() > 0){ for(int i=0; i<quearray.length(); i++){ try { jsonobject queobj = quearray.getjsonobject(i); string queviewid = queobj.getstring("viewid"); //viewid of que object @ position jsonobject viewidobj = viewidjsnobject.getjsonobject(queviewid); //get json object against viewid if(viewidobj != null) { //now add these value que object @ position string name = viewidobj.getstring("name"); string param = viewidobj.getstring("param"); queobj.put("name", name); queobj.put("param", param); } } catch (jsonexception jse) { jse.printstacktrace(); } } } //now que array contains final merged data, convert arraylist<your_model>.
Comments
Post a Comment