本文目錄一覽:
php動態調用資料庫輸出json
php代碼如下:
?php
$arr = array
(
‘id’=’1111’,
‘url’=’../test.php’,
‘artist’=’aaaaaa’,
‘title’=’this a title’,
‘albu’=’dddddddd’,
‘img’=’image.gif’
);
$jsonencode = json_encode($arr);
echo $jsonencode;
?
返回的結果如下:
{“id”:”1111″,”url”:”..\/test.php”,”artist”:”aaaaaa”,”title”:”this a title”,”albu”:”dddddddd”,”img”:”image.gif”}
資料庫數據怎麼動態生成json文件?
你肯定是先用ResultSet將數據讀出來,然後封裝成一個對象,再把對象給序列化成JSON,寫給Response
js如何動態獲取資料庫中的json數組,取出後又怎麼輸出呢?
js要組合其他程序才能獲取資料庫中的數據吧
然後使用以下兩種方法之一把json轉為object使用
script
var b = ‘{“t”: 0, “b”: “adfjierg”}’;
try{
var a = (new Function(‘return’ + b))();
document.write(typeof(a));
}catch(e){
document.write(‘error’);
}
var c=eval(‘(‘+b+’)’);
document.write(typeof(c));
/script
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/160824.html