新聞中心
php轉(zhuǎn)換成json數(shù)據(jù)格式
json和php數(shù)組 格式的互相轉(zhuǎn)換,參考如下:$php_json = json_encode($json_arr); //把php數(shù)組格式轉(zhuǎn)換成 json 格式的數(shù)據(jù)echo $php_json;$php_json = json_decode($php_json); //再把json格式的數(shù)據(jù)轉(zhuǎn)換成php數(shù)組print_r($php_json);json數(shù)組$json = '[{"id":"22","name":"33","descn":"44"}]'; //json格式的數(shù)組轉(zhuǎn)換成 php的數(shù)組$arr = (Array)json_decode($json);echo $arr[0]-id; //用對(duì)象的方式訪問(wèn)

創(chuàng)新互聯(lián)秉承實(shí)現(xiàn)全網(wǎng)價(jià)值營(yíng)銷的理念,以專業(yè)定制企業(yè)官網(wǎng),成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站,小程序定制開發(fā),網(wǎng)頁(yè)設(shè)計(jì)制作,移動(dòng)網(wǎng)站建設(shè),成都全網(wǎng)營(yíng)銷推廣幫助傳統(tǒng)企業(yè)實(shí)現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級(jí)專業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對(duì)客戶都以感恩的心態(tài)奉獻(xiàn)自己的專業(yè)和所長(zhǎng)。
像這樣的問(wèn)題很常見(jiàn),沒(méi)必要在到處問(wèn),你多在后盾找找就不必這么麻煩了
php轉(zhuǎn)換成json數(shù)據(jù)格式是怎么轉(zhuǎn)換的?
其實(shí)就是把這3個(gè)結(jié)果并成一個(gè)數(shù)組,再轉(zhuǎn)就是了\x0d\x0a\x0d\x0a例如,\x0d\x0a$res1=mysql_query($sql1);\x0d\x0a\x0d\x0a$res2=mysql_query($sql2);\x0d\x0a\x0d\x0a$res3=mysql_query($sql3);\x0d\x0a\x0d\x0a定義一個(gè)新的數(shù)組$a=array();\x0d\x0a\x0d\x0a將3個(gè)結(jié)果壓入這個(gè)新的數(shù)組\x0d\x0aarray_push($a,$res1);\x0d\x0a\x0d\x0aarray_push($a,$res2);\x0d\x0a\x0d\x0aarray_push($a,$res3);\x0d\x0a\x0d\x0a最后轉(zhuǎn)義輸出\x0d\x0aechojson_encode($a);\x0d\x0a\x0d\x0aLZ遇到問(wèn)題不要?dú)怵H呀
PHP json數(shù)據(jù)寫入到j(luò)son文件,讀取json文件
// 生成一個(gè)PHP數(shù)組
$data = array();
$data['name'] = 'admin';
$data['pwd'] = '123456';
// 把PHP數(shù)組轉(zhuǎn)成JSON字符串
$json_string = json_encode($data);
// 寫入文件
file_put_contents('user.json', $json_string);
// 從文件中讀取數(shù)據(jù)到PHP變量
$json_string = file_get_contents('user.json');
// 把JSON字符串轉(zhuǎn)成PHP數(shù)組
$data = json_decode($json_string, true);
// 顯示出來(lái)看看
var_dump($data)
網(wǎng)站標(biāo)題:php數(shù)據(jù)轉(zhuǎn)json數(shù)組 json數(shù)組轉(zhuǎn)java數(shù)組
路徑分享:http://www.dlmjj.cn/article/hgppdj.html


咨詢
建站咨詢
