2

JSONReader を使用して JSON ファイルから情報を取得しようとしています (PHP 構成に JSONReader を実装しました)。また、単純な JSON ファイル (以下を参照) から配列全体 (部分、 Home Lawrence Library はどこにあります) で、私はこれに苦労しています。

正直なところ、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