相关疑难解决方法(0)

如何使用PHP从JSON中提取数据?

这是一个一般参考问题和答案,涵盖了许多永无止境的"如何访问我的JSON中的数据?" 的问题.它可以处理在PHP中解码JSON和访问结果的广泛基础知识.

我有JSON:

{
    "type": "donut",
    "name": "Cake",
    "toppings": [
        { "id": "5002", "type": "Glazed" },
        { "id": "5006", "type": "Chocolate with Sprinkles" },
        { "id": "5004", "type": "Maple" }
    ]
}
Run Code Online (Sandbox Code Playgroud)

如何在PHP中解码并访问结果数据?

php json

198
推荐指数
3
解决办法
25万
查看次数

使用php打印JSON对象

我在这里有JSON文件,我想用JSON打印该对象,

JSON格式

[{"text": "Aachen, Germany - Aachen/Merzbruck (AAH)"}, {"text": "Aachen, Germany - Railway (ZIU)"}, {"text": "Aalborg, Denmark - Aalborg (AAL)"}, {"text": "Aalesund, Norway - Vigra (AES)"}, {"text": "Aarhus, Denmark - Aarhus Airport (AAR)"}, {"text": "Aarhus Limo, Denmark - Aarhus Limo (ZBU)"}, {"text": "Aasiaat, Greenland - Aasiaat (JEG)"}, {"text": "Abadan, Iran - Abadan (ABD)"}]
Run Code Online (Sandbox Code Playgroud)

我尝试了以下方法,

<?php   
  $jsonurl='http://website.com/international.json'; 
  $json = file_get_contents($jsonurl,0,null,null);  
  $json_output = json_decode($json);        
  foreach ($json_output as $trend)  
  {         
   echo "{$trend->text}\n";     
  } 
?>
Run Code Online (Sandbox Code Playgroud)

但这没有用,谁能帮助我了解我在做什么错。

php json

5
推荐指数
2
解决办法
5万
查看次数

标签 统计

json ×2

php ×2