我想用PHP从嵌套的JSON文件中检索一个值。我创建了以下代码:
<?php
$string = file_get_contents("https://api.abc");
$json = json_decode($string,true);
foreach ($json['contacts'][0]['properties']['company'] as $person) {
echo $person['value'];
}
?>
它只会给我1个结果,只给出值的第一个字母。如何获得更多结果,而不仅仅是第一个字母?
{
"contacts": [{
"addedAt": 1414182103652,
"vid": 2,
"canonical-vid": 2,
"merged-vids": [],
"portal-id": 448845,
"is-contact": true,
"properties": {
"firstname": {
"value": "Andre"
},
"lastmodifieddate": {
"value": "1472024018755"
},
"company": {
"value": "test"
},
"lastname": {
"value": "Jansen"
}
},
答案 0 :(得分:0)
试试这个,
仅在$person
$person['value']
$json = json_decode($string,true);
foreach ($json['contacts'][0]['properties']['company'] as $person) {
echo $person;
}
<强> DEMO 强>