阅读了我能找到的所有文章后,我想知道 json 数据是否有效。
我正在使用 php 发出此请求:
$myjson= file_get_contents('http://slhassall.rightboatexpert.com/api/boats');
var_dump(json_decode($myjson));
这会将以下内容转储到页面,它是有效的 json 吗?
object(stdClass)[1]
public 'pagination' =>
object(stdClass)[2]
public 'total' => int 32
public 'num_per_page' => int 25
public 'page' => int 1
public 'results' =>
array (size=25)
0 =>
object(stdClass)[3]
public 'id' => int 54
public 'manufacturer' => string 'Utrecht' (length=7)
public 'condition' => string 'used' (length=4)
public 'model' => string 'Iron Sailing Barge' (length=18)
public 'marketing_status' => string 'For Sale' (length=8)
public 'year' => null
public 'stock_number' => null
public 'location' => string 'Suffolk' (length=7)
public 'description' => string 'Clipper design. Built in Utrecht 1988, 25m in
length, an elegantly converted Dutch sailing barge with fantastic internal and external
social entertainment /display spaces. Suitable for corporate or pri' (length=201)
public 'sale_status' => string 'For Sale' (length=8)
public 'price' => int 149000
public 'currency' => string 'GBP' (length=3)
public 'thumbnail' => string '/api/images/262' (length=15)
public 'boat_image_id' => int 262
1 =>
object(stdClass)[4]
public 'id' => int 51
public 'manufacturer' => string ' Wood' (length=5)
public 'condition' => string 'used' (length=4)
public 'model' => string 'MFV/Guard vessel ' (length=17)
public 'marketing_status' => string 'For Sale' (length=8)
public 'year' => int 1959
public 'stock_number' => null
public 'location' => string 'Great Yarmouth, Norfolk UK' (length=26)
public 'description' => string '' (length=0)
public 'sale_status' => string 'For Sale' (length=8)
public 'price' => int 35000
public 'currency' => string 'GBP' (length=3)
public 'thumbnail' => string '/api/images/219' (length=15)
public 'boat_image_id' => int 219
2 =>
我问是因为当我尝试连接到节点时:
$array = (json_decode($myjson));
echo $array->boat->manufacturer;
我收到此错误:
注意:未定义的属性:第 6 行 C:\wamp\www\json\index.php 中的 stdClass::$boat
注意:尝试在第 6 行的 C:\wamp\www\json\index.php 中获取非对象的属性
第 6 行是 echo 语句。我用谷歌搜索了这些错误代码,但无法弄清楚。
任何帮助,将不胜感激。
谢谢