我有那個json數(shù)據(jù){"@attributes":{"titleID":"24151"},"artist":"ALMKLAUSI & SPECKTAKEL","title":"Mama Laudaaa","label":"Xtreme Sound"}但我需要這樣的數(shù)據(jù){titleID":"24151","artist":"ALMKLAUSI & SPECKTAKEL","title":"Mama Laudaaa","label":"Xtreme Sound"}
1 回答

滄海一幻覺
TA貢獻1824條經驗 獲得超5個贊
您可以使用foreach循環(huán)獲取此輸出。
代碼:
<?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){
if($key== '@attributes'){
$key = key($value);
$value= $value[key($value)];
}
$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"}
- 1 回答
- 0 關注
- 132 瀏覽
添加回答
舉報
0/150
提交
取消