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

时间:2015-07-10 12:53:35

标签: php json parsing bigdata jsonreader

我正在尝试使用JSONReader从JSON文件中检索信息(我已经将JSONReader实现为我的PHP配置)并且我试图从一个简单的JSON文件(见下文)中获取有关数组整个部分的信息(部分,家庭劳伦斯图书馆所在地),我正在努力解决这个问题。

老实说,我不知道如何正确使用JSONReader。

这是我的代码:

 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:\n"; 
             break;
        case JSONReader::ARRAY_END: 
             echo "Array end.\n"; 
             break; 
        case JSONReader::VALUE: 
             echo " - " . $reader->value . "\n"; 
             break; 
     }
} 
$reader->close(); 
?> 

它只是打印数组的开始和数组结束,但不打印该值。

JSON代码:

{
"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": ""
    }
] }

链接到JSONReader文档:https://github.com/shevron/ext-jsonreader

顺便说一句,我正在尝试解析大JSON文件,所以请不要建议使用json_decode或curl方法。

0 个答案:

没有答案