doulao7998636570 2014-12-02 02:13
浏览 36
已采纳

用PHP读取JSON文件

I'm trying to read a JSON with a php array. The JSON file is using a format that I am not familiar with and I don't know how to write my PHP array so it could read the file.

JSON file in question can be found here: http://nhlwc.cdnak.neulion.com/fs1/nhl/league/teamroster/ANA/iphone/clubroster.json

The format is giving me hard time because 1) it is starting with a time stamp that my array cannot read and 2) the file is separated between the value position, means that I have a closing statement ' }] ' before the end of the file - seems like they separated category

My PHP array that work with more standard array :

function myFunction(response) {
    var arr = JSON.parse(response);
    var i;
    var out = "<table>";

    for(i = 0; i < arr.length; i++) {
        out += "<tr><td>" + 
        arr[i].position +
        "</td><td>" +
        arr[i].weight +
        "</td><td>" +
        arr[i].height +
        "</td></tr>";
    }
out += "</table>"
document.getElementById("id01").innerHTML = out;

}

thank you

  • 写回答

2条回答 默认 最新

  • douchuang4402 2014-12-02 02:30
    关注

    It is called JSON, not JSCON. The code you posted is JavaScript, not PHP.

    Here is an example of how you could read the JSON you provided with PHP:

    <?php
        $result = file_get_contents("http://nhlwc.cdnak.neulion.com/fs1/nhl/league/teamroster/ANA/iphone/clubroster.json");
        $json = json_decode($result);
        foreach ($json->goalie as $player) {
            echo $player->name . '</br>';
        }
    ?>
    

    This will print each goalie's name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?