无法使用PHP从JSON获取数据

无法使用PHP从JSON获取数据,php,json,Php,Json,在创建此线程之前,我已经搜索了很多,我无法单独解决我的问题 <?php $str = file_get_contents('private url'); $json = json_decode($str); $json = json_decode($str, true); foreach($json as $x){ $new_str = file_get_contents('private url/'.$x["anomaly

在创建此线程之前,我已经搜索了很多,我无法单独解决我的问题

<?php
      $str = file_get_contents('private url');
      $json = json_decode($str);
      $json = json_decode($str, true);
      foreach($json as $x){
         $new_str = file_get_contents('private url/'.$x["anomaly_id"]);
         $new_json = json_decode($new_str);
         $new_json = json_decode($new_str, true);
         foreach($new_json as $new_x){
            echo  "<tr> <td data-title='Prefix'>".$new_x["prefix"]. "</td></tr>";
        }
      }
?>
Json:

另外,我不能给出URL,它是私有的,不是我的。
我不知道如何解决这个问题。你能帮我吗?

似乎你引用了错误的var尝试访问$new\u x(而不是$x2)

foreach($new\u json作为$new\u x){
回显“$new_x[“前缀]”;
}

似乎您引用了错误的var尝试访问$new\u x(而不是$x2)

foreach($new\u json作为$new\u x){
回显“$new_x[“前缀]”;
}
由于数组中只有一个级别,因此看起来您是在“过度迭代”,请删除foreach循环,直接访问它:

  $str = file_get_contents('private url');
  $json = json_decode($str, true);
  foreach($json as $x){
     $new_str = file_get_contents('private url/'.$x["anomaly_id"]);
     $new_json = json_decode($new_str, true);
     echo  "<tr> <td data-title='Prefix'>".$new_json["prefix"]. "</td></tr>";
  }
$str=file\u get\u contents('private url');
$json=json_decode($str,true);
foreach($json作为$x){
$new_str=file_get_contents('private url/'。$x[“异常id”);
$new_json=json_decode($new_str,true);
echo“$new_json[“prefix”]”;
}
由于数组中只有一个级别,因此看起来您是在“过度迭代”,请删除foreach循环,直接访问它:

  $str = file_get_contents('private url');
  $json = json_decode($str, true);
  foreach($json as $x){
     $new_str = file_get_contents('private url/'.$x["anomaly_id"]);
     $new_json = json_decode($new_str, true);
     echo  "<tr> <td data-title='Prefix'>".$new_json["prefix"]. "</td></tr>";
  }
$str=file\u get\u contents('private url');
$json=json_decode($str,true);
foreach($json作为$x){
$new_str=file_get_contents('private url/'。$x[“异常id”);
$new_json=json_decode($new_str,true);
echo“$new_json[“prefix”]”;
}


谢谢,我更改了,错误是相同的。请更新您的问题并添加JSON文件示例。。因此,我们可以评估可能的内容(仅供参考,这不是一个有效的解决方案,请删除)谁对这个错误的答案进行了投票?谢谢,我已更改,错误相同。更新您的问题并添加JSON文件示例。。因此,我们可以评估可能的内容(仅供参考,这不是一个有效的解决方案,请删除)谁对这个错误的答案投了赞成票?…除非我误解您想要所有
前缀
元素,包括
$new_json['prefix\u id']['prefix']
。什么是真实/有效的json值?我们都可以做自己的假设。谢谢!现在它工作得很好@朱塞佩你投票支持阿比德的回答了吗?这实际上并不是一个答案,而是一条注释,通知您发布的json字符串无效。阿比德要求你改进你的问题(你应该这样做),但对非答案/解决方案进行投票是对不恰当的张贴的奖励。@朱塞佩·阿比德将不太可能在适当的位置张贴他的建议,同时在他的答案上获得代表分……除非我误解你想要所有
前缀
元素,包括
$new\u json['prefix\u id']['prefix']
。什么是真实/有效的json值?我们都可以做自己的假设。谢谢!现在它工作得很好@朱塞佩你投票支持阿比德的回答了吗?这实际上并不是一个答案,而是一条注释,通知您发布的json字符串无效。阿比德要求您改进您的问题(您应该这样做),但对非答案/解决方案进行投票是对不适当的张贴的奖励。@Giuseppe Abid不太可能在适当的位置张贴他的建议,同时在其答案上获得代表分。您张贴的json字符串无效。请改进你的问题。提供真实/准确的数据。在这一页上,我并不是想欺负别人——这只是一个页面清理。因此,读者从清晰的问题和有用/正确的答案中受益最大。任何其他操作都只会导致混乱和页面膨胀。您发布的json字符串无效。请改进你的问题。提供真实/准确的数据。在这一页上,我并不是想欺负别人——这只是一个页面清理。因此,读者从清晰的问题和有用/正确的答案中受益最大。其他任何事情都只会导致混乱和页面膨胀。
foreach($new_json as $new_x){
 echo  "<tr> <td data-title='Prefix'>".$new_x["prefix"]. "</td></tr>";
}
  $str = file_get_contents('private url');
  $json = json_decode($str, true);
  foreach($json as $x){
     $new_str = file_get_contents('private url/'.$x["anomaly_id"]);
     $new_json = json_decode($new_str, true);
     echo  "<tr> <td data-title='Prefix'>".$new_json["prefix"]. "</td></tr>";
  }