json_decode() 使用总结

json使用总结

1、php json_encode() 返回 [] 与 {}

  1. json_decode() 原样输出:
    encode之前是数组,decode为数组;
    encode之前是对象,decode为对象;
  2. json_decode(a, true) 数组格式输出

 Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [1] => Array
        (
        )

    [2] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )
)
?>
 Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [1] => Array
        (
        )

    [2] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )
)
?>
 stdClass Object
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [1] => stdClass Object
        (
        )

    [2] => stdClass Object
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )
)
?>
 Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [1] => Array
        (
        )

    [2] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )
)
?>

参考:https://www.codelovers.cn/article/20180629104213.html

你可能感兴趣的:(PHP)