How Php To Json converted? -


we can convert php code how json format? may have not accurately php coding beginner learn because i'm new . i'll integrated android application. draw pictures how information ?

for example, want this: http://mikepenz.com/android/unsplash/pictures

<?php // don't forget change 'username' actual tumblr name $request = 'http://walltumbler.tumblr.com/api/read/json'; $ci = curl_init($request); curl_setopt($ci, curlopt_returntransfer, true); $input = curl_exec($ci); // tumblr json doesn't come in standard form, str replace needed $input = str_replace('var tumblr_api_read = ','',$input); $input = str_replace(';','',$input); // parameter 'true' necessary output php array $value = json_decode($input, true); $content =  $value['posts']; // number of items want display $item = 98988; // tumblr provides various photo size, case choose 75x75 square 1 $type = 'photo-url-1280';   ?> {     "limit": null,     "offset": 0,     "count": 2442,     "total": 2442,     "data": [  <?php  ($i=0;$i<=$item;$i++) {     if ($content[$i]['type'] == 'photo') {         echo '           {             "id": '.$i.';             "author": "paul jarvis",             "image_src": "' . $content[$i][$type] . '",             "color": "#7f7873",             "date": "2015-01-21 19:20:00",             "modified_date": "2014-09-01 22:36:53",             "width": 2500,             "height": 1667,             "ratio": 1.4997000694275,             "featured": 1,             "temp_id": 1         }';       $string = rtrim($item, ', ');     } } ?> ]} 

try using json_encode() function

<?php  $request = 'http://walltumbler.tumblr.com/api/read/json'; $ci = curl_init($request); curl_setopt($ci, curlopt_returntransfer, true); $input = curl_exec($ci); $input = str_replace('var tumblr_api_read = ','',$input); $input = str_replace(';','',$input); $value = json_decode($input, true); $content =  $value['posts']; $item = 98988; $type = 'photo-url-1280';  $photos_array = array();  ($i=0;$i<=$item;$i++) {     if ($content[$i]['type'] == 'photo') {         $photos_array[] = array(             'id' => $i,             'author' => 'paul jarvis',             // continue values...         );     } }  $json_data = array(     'limit'  => null,     'offset' => 0,     'count'  => 2442,     'total'  => 2442,     'data'   => $photos_array );  // use json_encode json data...  echo json_encode( $json_data ); 

hope helps


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -