Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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/4/json/14.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
Php JSON解码子数组_Php_Json_Decode - Fatal编程技术网

Php JSON解码子数组

Php JSON解码子数组,php,json,decode,Php,Json,Decode,我试图通过一堆此类JSON代码(通过url)使用PHP实现foreach循环 我能够得到“a”、“c”、“e”和“f”的关键值 我使用此代码来执行此操作 $url = 'http://url.com/json'; $jsondata = file_get_contents($url); $jso = json_decode($jsondata, TRUE); $data = $json['abc']; foreach ($data as $feature) { echo $feature

我试图通过一堆此类JSON代码(通过url)使用PHP实现foreach循环

我能够得到“a”、“c”、“e”和“f”的关键值

我使用此代码来执行此操作

$url = 'http://url.com/json';

$jsondata = file_get_contents($url);

$jso = json_decode($jsondata, TRUE);

$data = $json['abc'];

foreach ($data as $feature)
{
echo $feature['a'];
}

当我尝试
echo$feature['b']时,
将显示“Array”
$feature['ba']
在x行显示
未定义的索引:ba:/test.php

如果循环使用
$json[“abc”][0]
键将是a、b、c、d、e和f

$url = 'http://url.com/json';
$jsondata = file_get_contents($url);
$json = json_decode($jsondata, TRUE);

$data = $json['abc'][0];
foreach ($data as $key => $value) {
    var_dump($key, $value);
}
“ba”
将是:
$json[“abc”][0][“b”][0][“ba”]


“dc”
将是:
$json[“abc”][0][“d”][1][“dc”]

您想要实现什么?预期的结果是什么?试试这个:
$feature['b']['ba']
谢谢你的快速回复!你的洞察力对我帮助很大!
$url = 'http://url.com/json';
$jsondata = file_get_contents($url);
$json = json_decode($jsondata, TRUE);

$data = $json['abc'][0];
foreach ($data as $key => $value) {
    var_dump($key, $value);
}