2

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

Tomas
  • 21
  • 2
  • Could you show some example code? – SJoshi Jul 10 '15 at 13:45
  • Sure, first I've tried to get it working with example code: inline `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(); ?>` and it is just printing array start and array end, but does not print the value. – Tomas Jul 11 '15 at 11:11
  • Welcome to Stack Overflow! I've edited the code from your comments into your post. You can do this kind of thing yourself, by using the "edit" link below your posts. In this way, we can see your code immediately and (hopefully) with a bit of formatting - this helps us to better diagnose the problem. Good luck and enjoy your stay! – S.L. Barth is on codidact.com Jul 12 '15 at 14:26
  • @Tomas di you ever figure this out? – Devin Dixon Dec 01 '18 at 00:03

0 Answers0