doulu6314 2013-08-30 14:29
浏览 72
已采纳

多个对象数组中的json_decode

I have a JSON array with multiple objects and trying to use json_decode to make an associate array.

Sample data

$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"
     }]';

Here's what I am doing:

$data = json_decode($json, true);

which gives me a NULL result. What am I doing wrong?

(I'm new to PHP.)

  • 写回答

4条回答 默认 最新

  • dpp66953 2013-08-30 14:37
    关注

    Create Validate Json Try this

    <?php
    $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);
    echo "<pre>" ;
    print_r($data);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记