java - How to write a json to add a list? -
i need create json this.
{ "list": [ { "description": "abc", "id": "music", "issent": "0" }, { "description": "abc", "id": "music", "issent": "0" } ] }
this code i'm using write json. not display values i'm getting through database.it repeats data last column of database
jsonobject jo = new jsonobject(); jsonarray ja = new jsonarray(); map<string, object> data = new hashmap<string, object>(); try { statement ac = dbl.getconnection().createstatement(); resultset r5 = ac.executequery("select * msg"); while (r5.next()) { system.out.println("value taken database" + r5.getstring("content")); data.put("description", r5.getstring("content")); data.put("id", r5.getstring("id")); data.put("issent",r5.getstring("issent")); ja.put(jo); } ja.put(data); system.out.println(data); jsonobject mainobj = new jsonobject(); ret = mainobj.put("list", ja).tostring(); }
jsonobject final = new jsonobject(); jsonarray ja = new jsonarray(); try { statement ac = dbl.getconnection().createstatement(); resultset r5 = ac.executequery("select * msg"); while(r5.next()){ system.out.println("value taken database"+r5.getstring("content")); jsonobject jo = new jsonobject(); jo.put("description", r5.getstring("content")); jo.put("id", r5.getstring("id")); jo.put("issent",r5.getstring("issent")); ja.put(jo); } ret= final.put("list", ja).tostring();
try above one. should work.
Comments
Post a Comment