简体   繁体   English

试图在(PHP)中获取非对象的属性

[英]Trying to get property of non-object in (PHP)

get error message:获取错误信息:

Notice: Trying to get property of non-object in C:\\xampp\\htdocs\\test.php on line 11注意:第 11 行尝试在 C:\\xampp\\htdocs\\test.php 中获取非对象的属性

This is my code:这是我的代码:

<?php
$json_url = "http://samp-stats.ru/web/api-12492.js";
$json     = file_get_contents($json_url);
$data     = json_decode($json);

echo "<pre>";
var_dump($json);
echo "</pre>";


for ($i = 0; $i < count($data->plinfo); $i++) {  
    $document->write($data->plinfo[$i]->name + ' - ' + $data->plinfo[$i]->score + '<br>');    
}


?>

The JSON is incorrectly formatted. JSON 格式不正确。

  • There should be nothing preceding the JSON, just the JSON. JSON 之前应该没有任何内容,只有 JSON。 So remove the var api = at the beginning.所以去掉开头的var api =
  • All object names and string values need to be in double quotes.所有对象名称和字符串值都需要用引号括起来。 So ip:'37.59.30.67' needs to read "ip":"37.59.30.67"所以ip:'37.59.30.67'需要读取"ip":"37.59.30.67"
  • No trailing commas at the end of a range, eg.范围末尾没有尾随逗号,例如。 {name:'Mariu$Bahaos',score:'48' }, ] . {name:'Mariu$Bahaos',score:'48' }, ] That trailing comma tells the parser to expect another object in the array.尾随逗号告诉解析器期待数组中的另一个对象。
  • No semi-colon at the end of your string.字符串末尾没有分号。 } is the end character for a JSON string. }是 JSON 字符串的结束字符。

Please read up on JSON at JSON.org请阅读JSON.org上的 JSON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM