[英]parsing json data in php from a url request
嘗試解析以下數據,但無法獲取正確的項目以回顯。 我究竟做錯了什么?
{
"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)
至
foreach ($json_data['organizations'] as $address)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.