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 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化
  • ¥15 搭建QEMU环境运行OP-TEE出现错误
  • ¥15 Minifilter文件保护
  • ¥15 有限元软件终止时间超过设定值
  • ¥15 onvif框架引用一直报错
  • ¥50 C#和C++混合编程,使用CLR托管,报错System.Runtime.InteropServices.SEHException
  • ¥30 .NET使用sqlite发布后报错