2

我正在尝试使用 JSONReader 从 JSON 文件中检索信息(我已经在我的 PHP 配置中实现了 JSONReader),并且我正在尝试从一个简单的 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 方法。

4

0 回答 0