gpt4 book ai didi

php - 多对象数组中的 json_decode

转载 作者:行者123 更新时间:2023-12-02 21:51:34 24 4
gpt4 key购买 nike

我有一个包含多个对象的 JSON 数组,并尝试使用 json_decode 来创建关联数组。

示例数据

$json='[{   
type: "cool",
category: "power",
name: "Robert Downey Jr.",
character: "Tony Stark / Iron Man",
bio: "cool kid"
},
{
type: "cool",
category: "power",
name: "Chris Hemsworth",
character: "Thor",
bio: "cool kid"
},
{
type: "NotCool",
category: "nothing",
name: "Alexis Denisof",
character: "The Other",
bio: "cool kid"
}]';

这就是我正在做的事情:

$data = json_decode($json, true);

这给了我一个NULL结果。我做错了什么?

(我是 PHP 新手。)

最佳答案

您的 JSON 字符串无效:键也需要加引号。使用JSONlint网站,检查 JSON 有效性。

关于php - 多对象数组中的 json_decode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18535384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com