如何在PHP中读取此JSON

时间:2018-11-19 12:36:58

标签: php arrays json

我有一个简单的JSON,想用PHP阅读。我当然缺少数组中的任何内容,任何人都可以指出我的错误。我玩这个简单的东西已经很长时间了。 这是JSON和php:

$string='[
    {
        "phone":"+91009999000",
        "name":"abcd",
        "typeid":1
    }
    {
        "phone":"+91009999222",
        "name":"efg",
        "typeid":2
    }
    {
        "phone":"+91009999444",
        "name":"hijhl",
        "typeid":1
    }
]';


$json_a = json_decode($string,true);            
$phone = $json_a[0]['phone'];
$full_name=$json_a[0]['courseid'];

echo "phone = " . $phone;
echo "<br>fullname = " . $full_name;

1 个答案:

答案 0 :(得分:2)

您在花括号附近缺少逗号。

应该是这样的:

$string='[
            {
                "phone":"+91009999000",
                "name":"abcd",
                "typeid":1
            },
            {
                "phone":"+91009999222",
                "name":"efg",
                "typeid":2
            },
            {
                "phone":"+91009999444",
                "name":"hijhl",
                "typeid":1
            }
        ]';