如何在php中划分json响应?

时间:2019-01-14 05:04:17

标签: php json

我是php和json的初学者。我想在php中分割json响应

<?php
 $number=$_REQUEST['n'];
$cat=$_REQUEST['cat'];

echo "This is a test page";

if($cat=="all"){ $url= "http://subscription.marketjs.com/api/portal_game/list/json/$number";}else{$url="http://subscription.marketjs.com/api/portal_game/list_by_genre/$cat/json/$number"; }

$ch = curl_init($url);                                                                      
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $result = curl_exec($ch);
echo $result=json_decode($result,true);
?>

当我回显此$result = curl_exec($ch);时,请以这种方式显示

{"status": {"code": 200}, "data": {"0": {"genres": "Family,Puzzle", "screenshot2_small": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/screenshots/2.jpg", "plays": 29, "language": "en", "title": "World of Words", "date_added": "07-17-2018", "screenshot1_small": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/screenshots/1.jpg", "icon_large": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/icons/128x128.png", "icon_medium": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/icons/96x96.png", "featured": "false", "url": "https://subscription.marketjs.com/serve?portal_id=5692266857365504&game_id=6368315800813568&branding_id=5169425925799936&ad_id=5185095820378112&portal_localization_id=6207741047603200", "banner_large": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/banners/1300x500.jpg", "banner_medium": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/banners/440x280.jpg", "short_description": "Find and match words, while travelling the world", "icon_small": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/icons/64x64.png", "banner_small": "https://cdn.marketjs.net/games/world-of-words/localization/en/media/graphics/promo/banners/180x120.jpg"}}}

我想这样显示以便于阅读

  { 
    "status": {"code": 200},  
    "data": { 
             "0": { // This is the index 
                "plays": 1,  "language": "en", 
                "title": "Social Blackjack",  
                "date_added": "02-03-2017",  
                "icon_large": "http://whitelabel-cdn.marketjs.com/games/social-blackjack/localization/en/media/graphics/promo/icons/128x128 .png",
          } 
      } 
   } 

0 个答案:

没有答案