views:

32

answers:

2

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?

A: 

Try:

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

echo json_encode($json);
Michael Robinson
nope that gets me the same thing...{"@attributes":{"abc_id":"8"},"0":"Event Name"}
tlflow
A: 

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);
Kevin Sedgley
Thanks for your help, but that didn't work for me (at least not yet)- but it got me thinking... to "cheat" I could explode and then trim away any excess stuff. That gets it working for now but I'm going to keep playing with what ideas you're giving me to see if it does work out. Thanks!
tlflow