duannue2455 2015-07-10 12:53
浏览 44

使用PHP中的JSONReader正确检索JSON文件中的信息

I am trying to retrieve information from a JSON file using JSONReader (I've implemented JSONReader to my PHP configuration) and I am trying to get the information from a simple JSON file (see below) about the whole part of the array (part, where Home Lawrence Library is) and I am struggling with this.

To be honest, I don't know how to use JSONReader properly.

This is my code:

 inline <?php $reader = new JSONReader();
 $reader->open('http://www.example.com/news.json'); 
 while ($reader->read()) { 
     switch($reader->tokenType) { 
         case JSONReader::ARRAY_START: 
             echo "Array start:
"; 
             break;
        case JSONReader::ARRAY_END: 
             echo "Array end.
"; 
             break; 
        case JSONReader::VALUE: 
             echo " - " . $reader->value . "
"; 
             break; 
     }
} 
$reader->close(); 
?> 

It is just printing array start and array end, but does not print the value.

JSON code:

{
"markers": [
    {
        "homeTeam": "Lawrence Library",
        "awayTeam": "LUGip",
        "markerImage": "images/red.png",
        "information": "Linux users group meets second Wednesday of each month.",
        "fixture": "Wednesday 7pm",
        "capacity": "",
        "previousScore": ""
    },
    {
        "homeTeam": "Hamilton Library",
        "awayTeam": "LUGip HW SIG",
        "markerImage": "images/white.png",
        "information": "Linux users can meet the first Tuesday of the month to work out harward and configuration issues.",
        "fixture": "Tuesday 7pm",
        "capacity": "",
        "tv": ""
    },
    {
        "homeTeam": "Applebees",
        "awayTeam": "After LUPip Mtg Spot",
        "markerImage": "images/newcastle.png",
        "information": "Some of us go there after the main LUGip meeting, drink brews, and talk.",
        "fixture": "Wednesday whenever",
        "capacity": "2 to 4 pints",
        "tv": ""
    }
] }

Link to the JSONReader documentation: https://github.com/shevron/ext-jsonreader

Btw, I am trying to parse big JSON files so please do not suggest to use json_decode or curl methods.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害