我有json数据,就这样说吧
$string='[{"main_menu_id":"1","main_menu_caption":"Home","main_is_get_from_page":"0","is_sub_menu":"0","main_url_page":"","sub_menu_caption":"","caption_type":"","sub_is_get_from_page":"","sub_url_page":"","sub_additional_param":""}]';
如何仅在此json数据中获取字段名称? 我期望的结果是main_menu_id,Main_menu_caption等。我需要提取keyname而不是值
答案 0 :(得分:2)
$string='[{"main_menu_id":"1","main_menu_caption":"Home","main_is_get_from_page":"0","is_sub_menu":"0","main_url_page":"","sub_menu_caption":"","caption_type":"","sub_is_get_from_page":"","sub_url_page":"","sub_additional_param":""}]';
$arrJson = array();
$arrJson = json_decode($string);
foreach($arrJson as $key=>$value){
foreach($value as $keyval=>$val){
echo $keyval."<br>";
}
}