开发者

JSON_encode adding too much stuff! How do I filter it all out?

开发者_如何学运维I'm calling in values using PHP to cURL a site's API. I'm able to pull the data in and put into an array just fine, but when using JSON, one of the attributes ($title) comes back with too much data.

For example, if I just do

echo $new_array[27]['title'];

-> I get "Event Name" but if I do

echo json_encode($new_array[27]['title']);

-> I get {"@attributes":{"abc_id":"8"},"0":"Event Name"}

I want to use JSON as this works with something else I'm doing, but is there a way I can strip out the {"@attributes":{"abc_id":"8"},"0": part leaving just the "Event Name" as a string by itself?


Try:

$json = $new_array[27]['title'];

echo json_encode($json);


I'm not sure what you have in your array there, so these are a guess!

You could try:

unset($new_array[27]['title']['@attributes']);

Or:

$a = array();
foreach($new_array[27]['title'] as $arr) {
    $a[] = $arr->__toString();
}
echo json_encode($a);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜