[英]JSON_encode adding too much stuff! How do I filter it all out?
我正在使用PHP調用值來卷曲站點的API。 我可以將數據提取並放入數組中,但是使用JSON時,其中一個屬性($ title)會返回過多數據。
例如,如果我只是做
echo $new_array[27]['title'];
->我得到“事件名稱”,但如果我知道
echo json_encode($new_array[27]['title']);
->我得到{“ @attributes”:{“ abc_id”:“ 8”},“ 0”:“事件名稱”}
我想使用JSON,因為這可以與我正在做的其他事情一起使用,但是有一種方法可以去除{“ @attributes”:{“ abc_id”:“ 8”},“ 0”:僅保留“事件名稱”本身是否為字符串?
嘗試:
$json = $new_array[27]['title'];
echo json_encode($json);
我不確定您的陣列中有什么,所以這是一個猜測!
您可以嘗試:
unset($new_array[27]['title']['@attributes']);
要么:
$a = array();
foreach($new_array[27]['title'] as $arr) {
$a[] = $arr->__toString();
}
echo json_encode($a);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.