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 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验