PHP 二维array转换json的实例讲解
PHP提供函数直接将array转换成json
json_encode($param_array);
若需要下面这种嵌套式如何处理呢?
{ "appid": "1500001105", "nonce": 32490, "timestamp": 1458195253, "signature": "bf13fe77f46a96edba1a0e2b84fce66580b2f50b", "param": { "userid": "bonnie" } }
先构成一个二级array,再调用json_encode转换即可。
$param = array( 'userid'=>'bonnie' ); $params = array( 'appid'=>'1500001105', 'nonce'=>$nonce, 'timestamp'=>$timestamp, 'signature'=>$signature, 'param'=>$param, ); $params_json = json_encode($params);
相关推荐
jzlixiao 2020-07-29
Leonwey 2020-06-01
singer 2019-12-13
doubinning 2019-12-02
lmseohy 2015-06-17
ciqingloveless 2019-03-21
olyqcool 2015-06-17
EdwardWong 2006-11-07
GuangkuoDing 2012-02-06
anningzhu 2017-07-18
liushuibufuqin 2017-12-12
allentony 2018-06-19
xinhao 2018-05-15
Amonos 2018-04-13
chouliqingke 2018-04-03