小编Ale*_*lan的帖子

注意:尝试获取非对象错误的属性

我试图从以下数据获取数据:

http://api.convoytrucking.net/api.php?api_key=public&show=player&player_name=Mick_Gibson

但如果我想用这段代码获取player_name变量:

<?  
$js = file_get_contents('http://api.convoytrucking.net/api.php?api_key=public&show=player&player_name=Mick_Gibson');
  $pjs = json_decode($js);
  var_dump($pjs->{'player_name'});
?>
Run Code Online (Sandbox Code Playgroud)

我收到错误:

注意:尝试在第9行+ var_dump()的**\htdocs\index.php中获取非对象的属性返回:NULL

var_dump($pjs) 收益:

array(1) { [0]=> object(stdClass)#52 (15) { ["player_name"]=> string(11) "Mick_Gibson" ["player_id"]=> int(88) ["rank"]=> string(12) "FIRE TURTLEE" ["lastseen"]=> int(1393797692) ["registration_date"]=> string(19) "2012-08-10 17:01:34" ["last_mission_date"]=> string(19) "2014-03-02 21:41:50" ["time_offset"]=> int(1) ["house_id"]=> int(611) ["fines"]=> int(0) ["wanted"]=> int(0) ["police_badge"]=> bool(true) ["vip"]=> bool(false) ["staff"]=> NULL ["stats"]=> object(stdClass)#53 (23) { ["score"]=> int(2941) ["convoy_score"]=> int(818) ["ARTIC"]=> int(515) ["DUMPER"]=> int(565) ["TANKER"]=> int(56) ["CEMENT"]=> int(163) ["TRASH"]=> int(7) ["ARMORED"]=> int(9) ["VAN"]=> int(501) ["TOW"]=> int(502) …
Run Code Online (Sandbox Code Playgroud)

php syntax-error notice

24
推荐指数
1
解决办法
24万
查看次数

标签 统计

notice ×1

php ×1

syntax-error ×1