【问题标题】:How to print a String from a json file in PHP [closed]如何从 PHP 中的 json 文件打印字符串 [关闭]
【发布时间】:2014-01-02 14:59:00
【问题描述】:

我有问题。 我想用 php scipt 打印出这个字符串在这个 JSON 文件中的字符串: http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500030916&mt_order_by=-role_hierarchy

它是:数据/描述

我希望你明白我的意思。

【问题讨论】:

    标签: php json printing


    【解决方案1】:

    使用jsondecode php函数。

    $url = 'http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500030916&mt_order_by=-role_hierarchy';
    $jsondata = file_get_contents($url); //json data from url
    $data = json_decode($jsondata,1); // convert json data to array
    echo $data['data']['description']; // access data using keys of array, mapped to properties in json
    

    【讨论】:

      【解决方案2】:

      使用json_decode

      $json_uri = 'http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500030916&mt_order_by=-role_hierarchy';
      
          $json = file_get_contents($json_uri);
          $data = json_decode($json,1); // convert json data to array
          $count = 1;
          foreach ($data['data'] as $key => $info) {
              echo $count++.' - '.$info['description'].'<br>';
          }
      

      【讨论】:

        猜你喜欢
        • 2018-12-27
        • 2017-10-05
        • 1970-01-01
        • 2021-04-03
        • 1970-01-01
        • 2011-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多