Can someone help me create a JSON object from a database?
Here is what JSON should look like:
{"devicelist":{ "device": [ {"id": "01", "type": "CAM", "name": "Livingroom"} {"id": "15", "type": "CAM", "name": "Kitchen"} ] }}
This is my code :
if (reg!=null) { try { con = ds.getConnection(); Statement select = con.createStatement(); ResultSet result=select.executeQuery("Select type,name,demo from register_device"); while (result.next()) { String type_json=result.getString("type"); String name_json=result.getString("name"); String id_json=result.getString("demo"); JSONArray arrayObj=new JSONArray(); } } catch(Exception e) { } }
I can get the selected type, name, demo from the database.
I do not know how to start JSON encoding.
java json
bharathi
source share