Excelption #1

Open
by Ghost opened 2 years ago · 1 comments
Ghost commented 2 years ago

Hi I keep getting and error when I parse data in the following format, sadly this comes from a 3rd party API so I cant change it

{
  "Success": true,
  "Status": "Ok",
  "Data": [
    {
      "timeLive": "43",
      "halfTimeScore": "0 - 0",
      "fullTimeScore": null,
      "firstTeamToScore": null,
      "homeTeamInfo": {
        "homeTeam": "Indonesia",
        "homeGoals": "0",
        "homeGoalsHalfTime": "0",
        "homeCorners": "0",
        "homeYellowCards": "0",
        "homeRedCards": "0",
        "homeShotsOnTarget": "0",
        "homeShotsOffTarget": "0",
        "homeAttacks": "0",
        "homeDangerousAttack": "0",
        "homePossession": "0",
        "homeFouls": 0,
        "avgGoalsHome": null,
        "teamID": "44CB1",
        "homeTeamForm": null

I dont think it likes the structure with the DATA at the top but im unsure how I can get round it

The error is
PHP Fatal error: Uncaught exception 'JSONStreamException' with message 'unexpected token at offset 0:

Hi I keep getting and error when I parse data in the following format, sadly this comes from a 3rd party API so I cant change it ``` { "Success": true, "Status": "Ok", "Data": [ { "timeLive": "43", "halfTimeScore": "0 - 0", "fullTimeScore": null, "firstTeamToScore": null, "homeTeamInfo": { "homeTeam": "Indonesia", "homeGoals": "0", "homeGoalsHalfTime": "0", "homeCorners": "0", "homeYellowCards": "0", "homeRedCards": "0", "homeShotsOnTarget": "0", "homeShotsOffTarget": "0", "homeAttacks": "0", "homeDangerousAttack": "0", "homePossession": "0", "homeFouls": 0, "avgGoalsHome": null, "teamID": "44CB1", "homeTeamForm": null ``` I dont think it likes the structure with the DATA at the top but im unsure how I can get round it The error is PHP Fatal error: Uncaught exception 'JSONStreamException' with message 'unexpected token at offset 0:
Owner

Hi. It's interesting that you've found this repo :)

I suspect you copy-pasted the example with enterArray() at the upper level, which is incorrect for objects. Call enterObject() to enter the top-level object, like:

<?php

require_once './JSONStream.php';

$fp = fopen('test.json', 'r');
$json = new JSONStream(function() use($fp) { return fread($fp, 262144); });
$json->enterObject();
while ($json->readValue($k))
{
    $json->readValue($v);
    var_dump([$k, $v]);
}
$json->exitObject();
fclose($fp);

You'll probably want to make multiple enterXXX() calls. For example, call enterArray() in the above example when $k is equal to "Data"...

Hi. It's interesting that you've found this repo :) I suspect you copy-pasted the example with enterArray() at the upper level, which is incorrect for objects. Call enterObject() to enter the top-level object, like: ```php <?php require_once './JSONStream.php'; $fp = fopen('test.json', 'r'); $json = new JSONStream(function() use($fp) { return fread($fp, 262144); }); $json->enterObject(); while ($json->readValue($k)) { $json->readValue($v); var_dump([$k, $v]); } $json->exitObject(); fclose($fp); ``` You'll probably want to make multiple enterXXX() calls. For example, call enterArray() in the above example when $k is equal to "Data"...
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.