解析JSON提要到PHP,然后添加数据?

解析JSON提要到PHP,然后添加数据?,php,parsing,json,Php,Parsing,Json,我有一个JSON提要,它是私有的(通过IP地址),我可以使用命令解析它 $json = file_get_contents("http://#"); 这就是feed的外观和命令的工作原理——当使用json_decode($json)时,它会正确地转储数据;或json_解码($json,true);我做了一个var转储 { "Holder": [ { "name": "Subholder One", "operato

我有一个JSON提要,它是私有的(通过IP地址),我可以使用命令解析它

$json = file_get_contents("http://#");
这就是feed的外观和命令的工作原理——当使用json_decode($json)时,它会正确地转储数据;或json_解码($json,true);我做了一个var转储

    {
    "Holder": [
        {
            "name": "Subholder One",
            "operators": [
        {
          "username": "User1",
          "status": 3
        },
        {
          "username": "User2",
          "status": 3
        },
        {
          "username": "User3",
          "status": 3
        },
        {
          "username": "User4",
          "status": 1
        }
      ]
    },
    {
      "name": "Subholder Two",
      "operators": [
        {
          "username": "User5",
          "status": 3
        }
      ]
    },
    {
      "name": "Subholder Three",
      "operators": [
        {
          "username": "User6",
          "status": 3
        }
      ]
    },
    {
      "name": "Subholder Four",
      "operators": [
        {
          "username": "User7",
          "status": 1
        },
        {
          "username": "User8",
          "status": 3
        },
        {
          "username": "User9",
          "status": 1
        }
      ]
    }
  ]
}
当我使用以下简单代码和一行数据时,使用nofile\u get\u内容,但使用一行数据时,它可以工作:

$obj = json_decode($json);
echo $obj->username;
echo $obj->status;
当我使用file\u get\u内容时,它不起作用

我想做的就是显示所有数据的用户名和状态(转换成我已经做过的短语的数字),并且只显示用户名。

例如,在用户1的配置文件页面上,我想解析他们的“用户名”和“状态”,将状态号转换为相应的短语并显示在屏幕上

我在这里摸不着头脑……所以我感激地接受了任何帮助。

试试看

  $obj = json_decode($json, true);

  echo $obj['username'];
  echo $obj['status'];
试试这个:

$request_url ="http://mysamplefeed.com/";
$requests = file_get_contents($request_url);
$my_response = json_decode($requests);
foreach($my_response->Holder as $item){
'<p>' .$item->username; . '</p>'
'<p>' .$item->status; . '</p>'
}
$request\u url=”http://mysamplefeed.com/";
$requests=file\u get\u contents($request\u url);
$my_response=json_decode($requests);
foreach($my_response->Holder as$item){
“”.$item->username;“

” “”.$item->status;“

” }
您没有有效的JSON数据。请将文件\u get\u contents结果粘贴到此处。也许这个函数不允许通过http获取内容?(php.ini)您能在json解码之前将您得到的内容粘贴到文件内容中作为结果吗?因为上面问题中粘贴的json代码是有效的Hanks已经尝试过了-不起作用:o(当我手动编写数据时,它起作用,从提要中提取数据时它不起作用。大家好-有人帮忙吗?从提要中调用时,它仍然不起作用:(PHP
echo
不起作用,但
print\r
起作用……问题是,如果username=User1,那么status=3,我希望能够单独使用……即在一组单独的页面上使用相关的用户信息和状态。。。