1

Here is the JSON array I received:

{"parse":{"title":"List of Arrow episodes", "pageid":37371793, "text":{"*":"<div class=\"mw-parser-output\"><h3><span id=\"Season_7_.282018.E2.80.9319.29\"></span><span class=\"mw-headline\" id=\"Season_7_(2018\u201319)\">Season 7 (2018\u201319)</span><span class=\"mw-editsection\"><span class=\"mw-editsection-bracket\">[</span><a href=\"/w/index.php?title=List_of ...}

I want to fetch the content under parse->text->*, but it's giving me an error. Here's what I've tried:

if ($data = json_decode(@file_get_contents($api_url))) {
    $content = $data->parse->text->*;
    $content = Parser::doTableStuff($content)
    header('Content-Type:text/html; charset=utf-8');
    echo $content;
}

After debugging, I identified the problem is in the line $content = $data->parse->text->*; When I tried doing: $content = $data->parse->text; it works, so I suspect that the * syntax is not right.

Edit: I tried enclose * with {} and [], but it still giving an error.

  • try to use the curly braces, `->{'*'}` like so – Kevin Jun 17 '19 at 00:58
  • 1
    or turn it into an array instead `json_decode(, true)`, then you get an array so you can use `['*']` – Kevin Jun 17 '19 at 00:59
  • I tried $content = $data[parse][text][*]; and $content = $data->parse->text->{*}; but it still gave me an error (the page is not loading). When I tried $content = $data[parse][text], the webpage loaded. – user11656483 Jun 18 '19 at 02:01
  • Please study the syntax in the duplicate more closely. You need to use quoting inside the curly braces. https://3v4l.org/uBR1K Your question will not be reopened because the duplicate provides a perfect resolution. – mickmackusa Jun 20 '19 at 08:33

0 Answers0