php数组转json字符串:

<?php 
    $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>"5"); 
    $test = json_encode($arr); 
    echo $test;
?>
       结果:

{"a":1,"b":2,"c":3,"d":4,"e":"5"}


       json字符串转数组(如下的true表示转为数组, 否则为obj对象):

<?php 
    $test = '{"a":1,"b":2,"c":3,"d":4,"e":"5"}';
    $arr = json_decode($test, true); 
    print_r($arr);
?>
       结果为:

Array
(
    [a] => 1
    [b] => 2
    [c] => 3
    [d] => 4
    [e] => 5
)

    

       OK,  顺便学习了一下json串格式哈。





本文转载:CSDN博客