search

Home  >  Q&A  >  body text

一维数组到json数据格式的转换,没输出来结果。老是在 $jsonObj_1=json_encode($array_1);处显示错误,不知道怎么回事?

<?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;
 
 
?>


静待花开静待花开2827 days ago1373

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-10-01 00:20:40

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-02-15 15:50:46

    是你的标点符号有问题啊,不是中文下的‘ ’而是在英文下的' '

       $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;


    ?>



    reply
    0
  • Cancelreply