PHP中数组转JSon和JSon转数组的实现

数组转JSon数据:

$array_1 = array(); //一维数组
	$array_2 = array(); //多维数组
	$array_1['username']='ericwolf';
	$array_1['age']=25;

	$array_2['menber']['aa']['username']='ericwolf';
	$array_2['menber']['aa']['age']=25;
	$array_2['menber']['bb']['username']='eeee';
	$array_2['menber']['bb']['age']=22;

	print_r($array_2);
	$jsonObj_1 = json_encode($array_1);
	$jsonObj_1 = json_encode($array_2);

JSon转数组,并打印:

$jsonStr = '{"key":"value","key1":"value1"}';
	$json2Array = json_decode($jsonStr,true);
	foreach($json2Array as $key=>$val) {
		echo $key."=".$val."
"; }


你可能感兴趣的:(php)