【问题标题】:Can't echo JSON Array in PHP [duplicate]无法在 PHP 中回显 JSON 数组 [重复]
【发布时间】:2018-04-04 05:47:40
【问题描述】:

我无法访问我的 json,想知道错误在哪里。

$json = json_encode($data);
// string(1065) "[{"id":"test123","key":["one",...

然后我对其进行解码以使其可通过以下命令访问:

$json = json_decode($json, true);

// Output:
array(3) {
  [0]=>
  array(4) {
    ["id"]=>
    string(14) "test123"

当我想回应它时,它给了我:

echo $json[0];

数组到字符串的转换

【问题讨论】:

  • print_r($json[0]);
  • $json[0] 是一个数组。你不能echo 一个数组。
  • echo $json[0]['id'];

标签: php json


【解决方案1】:

print_r 用于数组,echo 用于显示string,这就是它给出错误的原因。

print_r($json);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-27
    • 2012-06-10
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多