i need to print all elements of object (obj) in php i need to print with echo obj : my code is : <?php $url = 'http://www.fiverr.com/gigs/gigs_as_json?host=search&type=single_query&query_string=pet&search_filter=rating&category_id=3&sub_category_id=49&limit=48'; $opts = array('http' => array( 'header' => 'Cookie: locale=en%3B0%3Bfalse; suggested_locale=1;', )); $ctx = stream_context_create($opts); $data = file_get_contents($url, false, $ctx); $data = gzdecode($data); $obj = json_decode($data); ?> PHP:
you could check to see how your data is structured with print_r($obj); PHP: It should be an array so you can just do $obj['somekey']
To print a array as a json object, you should do this: echo json_encode($obj); PHP: It looks like you are doing a json_decode, i don't see where it would already be a json object?
Data is coming in json encoded format and you are decoding the json to object. You cannot use echo for json decoded as it is an object. json_decode($data) -> returns Object json_decode($data) -> returns array if you echo the json decoded output it displays their respective datatype as object or array. Better use var_dump or print_r. If you want to display elements in object use echo $obj->key; displays the value of that key.