将 Json 数组转换为简单的 Json

我有那个json数据

{"@attributes":{"titleID":"24151"},"artist":"ALMKLAUSI & SPECKTAKEL","title":"Mama Laudaaa","label":"Xtreme Sound"}

但我需要这样的数据

{titleID":"24151","artist":"ALMKLAUSI & SPECKTAKEL","title":"Mama Laudaaa","label":"Xtreme Sound"}


拉丁的传说
浏览 158回答 1
1回答

沧海一幻觉

您可以使用foreach循环获取此输出。代码:<?php$str ='{"@attributes":{"titleID":"24151"},"artist":"ALMKLAUSI & SPECKTAKEL","title":"Mama Laudaaa","label":"Xtreme Sound"}';$arr = json_decode($str,true);$final_arr= array();foreach($arr as $key=>$value){&nbsp; &nbsp; if($key== '@attributes'){&nbsp; &nbsp; &nbsp; &nbsp; $key = key($value);&nbsp; &nbsp; &nbsp; &nbsp; $value= $value[key($value)];&nbsp; &nbsp; }&nbsp; &nbsp; $final_arr[$key]= $value;}$final_str = json_encode($final_arr);print_r($final_str);exit;输出:{"titleID":"24151","artist":"ALMKLAUSI & SPECKTAKEL","title":"Mama Laudaaa","label":"Xtreme Sound"}
打开App,查看更多内容
随时随地看视频慕课网APP