自己模擬了一點(diǎn)json數(shù)據(jù)存放在了數(shù)據(jù)庫一個(gè)表中大家可以自己模擬
創(chuàng)新互聯(lián)主營綏江網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都App制作,綏江h(huán)5微信小程序開發(fā)搭建,綏江網(wǎng)站營銷推廣歡迎綏江等地區(qū)企業(yè)咨詢
{"1":{"id":"1","name":"asd","type":"1","value":"1L,4L"}} {"2":{"id":"2","name":"kjf","type":"1","value":"1L,4L"}} {"3":{"id":"3","name":"sss","type":"1","value":"1L,4L"}}
下面我用的pdo執(zhí)行的php文件
'SET NAMES \'UTF8\''); $pdo = new PDO($dsn,$user,$pwd,$options); $sql="select id,json from ecs_json"; $res=$pdo->query($sql); $row = $res->fetchAll(); // $row是一個(gè)含有json字段鍵值得二維數(shù)組 //打印結(jié)果 Array ( [0] => Array ( [id] => 1 [0] => 1 [json] => {"1":{"id":"1","name":"asd","type":"1","value":"1L,4L"}} [1] => {"1":{"id":"1","name":"asd","type":"1","value":"1L,4L"}} ) [1] => Array ( [id] => 2 [0] => 2 [json] => {"2":{"id":"2","name":"kjf","type":"1","value":"1L,4L"}} [1] => {"2":{"id":"2","name":"kjf","type":"1","value":"1L,4L"}} ) [2] => Array ( [id] => 3 [0] => 3 [json] => {"3":{"id":"3","name":"sss","type":"1","value":"1L,4L"}} [1] => {"3":{"id":"3","name":"sss","type":"1","value":"1L,4L"}} ) ) //定義一個(gè)空數(shù)組 把二維組里json解析后放進(jìn)新數(shù)組中 $json = array(); foreach ($row as $k=>$v){ //json新數(shù)組中放入我需要的id 和 json 的二維數(shù)組鍵 $json[$k]['id'] =$v['id']; //把鍵值為json的json串轉(zhuǎn)換成數(shù)組 放到新數(shù)組中 $json[$k]['json'] =json_decode($v['json'],true); //轉(zhuǎn)換成數(shù)組的json串 //Array ( [3] => Array ( [id] => 3 [name] => sss [type] => 1 [value] => 1L,4L ) ) } echo json_encode($json); exit;
前端ajax接收輸出
前端接收json 姓名