我以JSON格式获取这样的值 -
{
"comments": [{
"name": "ABC",
"desc": "Hello...",
"values": [{
"status": "fine",
"label": ""
}]
}, {
"name": "XYZ",
"desc": "Good Morning..",
"values": [{
"status": "fine",
"label": "happy"
}]
}]
}
但我不想要第一个数组名称意味着我需要这样的结果 -
[{
"name": "ABC",
"desc": "Hello...",
"values": [{
"status": "fine",
"label": ""
}]
}, {
"name": "XYZ",
"desc": "Good Morning..",
"values": [{
"status": "fine",
"label": "happy"
}]
}]
需要帮助...
答案 0 :(得分:3)
这样做......
<?php
$json='{
"comments": [{
"name": "ABC",
"desc": "Hello...",
"values": [{
"status": "fine",
"label": ""
}]
}, {
"name": "XYZ",
"desc": "Good Morning..",
"values": [{
"status": "fine",
"label": "happy"
}]
}]
}';
$arr=json_decode($json,1);
echo json_encode($arr['comments']);
输出:
[{"name":"ABC","desc":"Hello...","values":[{"status":"fine","label":""}]},{"name":"XYZ","desc":"Good Morning..","values":[{"status":"fine","label":"happy"}]}]
答案 1 :(得分:0)
试试这个:
$data = '[{
"name": "ABC",
"desc": "Hello...",
"values": [{
"status": "fine",
"label": ""
}]
}, {
"name": "XYZ",
"desc": "Good Morning..",
"values": [{
"status": "fine",
"label": "happy"
}]
}]';
$return = json_decode($data, true);
foreach ($return as $key => $value){
unset($return[$key]['name']);
}
echo '<pre>';
print_r($return);
echo '</pre>';