<?php $array_1= array();//一维数组; $array_2= array();//二维数组; $array_1[’username’]="dfdsf"; $array_1[’age’]=25; $array_2[’nember’][’shjsh’][’username’]="dfdsf"; $array_2[’nember’][’shjsh’][’age’]=25; $array_2[’nember’][’hjhj’][’username’]="ghgj"; $array_2[’nember’][’hjhj’][’age’]=27; //print_r($array_2); $jsonObj_1=json_encode($array_1); echo $jsonObj_1; ?>
Conversion of one-dimensional array to json data format, no result is output. An error always appears at $jsonObj_1=json_encode($array_1);, I don’t know what’s going on? -PHP Chinese website Q&A-Conversion of one-dimensional array to json data format, no result is output. An error always appears at $jsonObj_1=json_encode($array_1);, I don’t know what’s going on? -PHP Chinese website Q&A
Let’s take a look and learn.
是你的标点符号有问题啊,不是中文下的‘ ’而是在英文下的' '
$array_1= array();//一维数组;
$array_2= array();//二维数组;
$array_1['username']="dfdsf";
$array_1['age']=25;
$array_2['nember']['shjsh']['username']="dfdsf";
$array_2['nember']['shjsh']['age']=25;
$array_2['nember']['hjhj']['username']="ghgj";
$array_2['nember']['hjhj']['age']=27;
//print_r($array_2);
$jsonObj_1=json_encode($array_1);
echo $jsonObj_1;
?>