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 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件