任何人都可以幫助我如何從數據庫創建JSON對象嗎?來自java數據庫的Json對象
這是JSON輸出應該是什麼樣子:
{「devicelist」:{
「device」: [
{「id」: 「01」, 「type」: 「CAM」, 「name」: 「Livingroom」}
{「id」: 「15」, 「type」: 「CAM」, 「name」: 「Kitchen」}
]
}}
這是我的代碼:
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)
{
}
}
我能夠獲得所選擇的類型,名稱,演示從數據庫中。
我不知道如何啓動JSON編碼。
哪個數據庫表列(如上所述)存儲JSON值? –
你好,我有相同的要求,我會非常感激,如果你能告訴我有什麼簡單和優雅的方式來使用Java標準庫(Java.net。*)將SQL轉換爲JSON或任何不是第三方的罐子。另外,「JSONARRAY」......這是第三方嗎?我會非常感謝,如果有人可以回覆我 – user3384231