Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从url请求解析php中的json数据_Php_Arrays_Json_Parsing - Fatal编程技术网

从url请求解析php中的json数据

从url请求解析php中的json数据,php,arrays,json,parsing,Php,Arrays,Json,Parsing,正在尝试分析以下数据,但在获取要回显的正确项时遇到问题。我做错了什么 { "total_results":12585, "organizations":[ { "ein":232669352, "strein":"23-2669352", "name":"AMERICAN HOME LIFE INTERNATIONAL INC", "sub_name":"AMERICAN HOME L

正在尝试分析以下数据,但在获取要回显的正确项时遇到问题。我做错了什么

{  
    "total_results":12585,
    "organizations":[  
      {  
         "ein":232669352,
         "strein":"23-2669352",
         "name":"AMERICAN HOME LIFE INTERNATIONAL INC",
         "sub_name":"AMERICAN HOME LIFE INTERNATIONAL INC",
         "city":"LANCASTER",
         "state":"PA",
         "ntee_code":"Q220",
         "raw_ntee_code":"Q220",
         "subseccd":3,
         "has_subseccd":true,
         "have_filings":true,
         "have_extracts":true,
         "have_pdfs":true,
         "score":417.01215
      },
      {  
         "ein":251691788,
         "strein":"25-1691788",
         "name":"HOME LIFE MINISTRIES",
         "sub_name":"HOME LIFE MINISTRIES",
         "city":"ANNVILLE",
         "state":"PA",
         "ntee_code":"X20",
         "raw_ntee_code":"X20",
         "subseccd":3,
         "has_subseccd":true,
         "have_filings":true,
         "have_extracts":true,
         "have_pdfs":true,
         "score":147.28578
      },
      {  
         "ein":240782824,
         "strein":"24-0782824",
         "name":"MIFFLINBURG AMERICAN LEGION HOME ASSOCIATION INC",
         "sub_name":"MIFFLINBURG AMERICAN LEGION HOME ASSOCIATION INC",
         "city":"MIFFLINBURG",
         "state":"PA",
         "ntee_code":null,
         "raw_ntee_code":null,
         "subseccd":7,
         "has_subseccd":true,
         "have_filings":true,
         "have_extracts":true,
         "have_pdfs":true,
         "score":145.12933
      },
以下是迄今为止我对代码的了解:

<?php
    $url = "https://projects.propublica.org/nonprofits/api/v2/search.json?
    q=%22american%20home%20life%20international%20inc%22&state%5Bid%5D=PA";
    $json = file_get_contents($url);
    $json_data = json_decode($json, true);
    foreach ($json['organizations'] as $address)
    {
        echo "items:". $address['ein'] ."\n";
    };
?>
改变

foreach ($json['organizations'] as $address)


请阅读。遇到的问题太广泛了,还需要格式化json示例。您正在尝试循环字符串,而不是$json_数据变量。请注意PHP提出的警告-它试图帮助您。foreach$json_data['organizations']as$address如果对您有帮助,请选择答案
foreach ($json_data['organizations'] as $address)