Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

get something form url

Comments in 'Plugin Development' started by xiaoq, Jul 3, 2015.

  1. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    I try to get something form url, but it didn't work, so can some one help me?
    This is my code:
    PHP:
       $url "http://plugin.3eeweb.com/";
                   
    $str=file_get_contents($url);
                    
    $son=json_decode($str);
                    
    $status $son->status;
       
    $player->sendMessage($status);
    InvalidStateException: "Trying to get property of non-object" (E_NOTICE) in "/ME/src/ME/Main" at line 35
    Line 35 is $status = $son->status;

    And this is my website:
    http://plugin.3eeweb.com/
    Last edited: Jul 3, 2015
    LDX likes this.
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    The first $url variable is mistyped as $utl. ;)
    Falk likes this.
  3. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    ...:) I type it wrong in the threads, so not this error...
    LDX likes this.
  4. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    $status = $son["status"];
    xiaoq likes this.
  5. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    It work, But now I didn't got the error, but still can't read the thing from the website
    And if I use Pastebin for my site, it will have this error:
    "Cannot use object of type stdClass as array"
    Last edited: Jul 3, 2015
  6. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    You need to set the second parameter in the json_decode function to true to use the results as an array. (Which I do every time.)
  7. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    I set $son=Json_decode($url,true);
    PEMapModder likes this.

Share This Page

Advertisement