我有以下摘录,取自http://developer.ean.com/docs/hotel-info/examples/rest-default-content
[ "HotelImages": {
"@size": "16",
"HotelImage": [
{
"hotelImageId": 4694179,
"name": "",
"category": 1,
"type": 0,
"caption": "Exterior",
"url": "/hotels/1000000/10000/5900/5900/5900_44_b.jpg",
"thumbnailUrl": "/hotels/1000000/10000/5900/5900/5900_44_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694182,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "/hotels/1000000/10000/5900/5900/5900_47_b.jpg",
"thumbnailUrl": "/hotels/1000000/10000/5900/5900/5900_47_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
}, ]
如何获取url
的数据?它实际上是一个我们应该附加http://images.travelnow.com/
示例:echo $data['HotelImages']['HotelImage']['url'];
但它给了我以下错误
未定义索引:HotelImages
我该如何解决这个问题?
答案 0 :(得分:0)
更正您的JSON sytax并尝试
$data ='{"HotelImages": {
"@size": "16",
"HotelImage": [
{
"hotelImageId": 4694179,
"name": "",
"category": 1,
"type": 0,
"caption": "Exterior",
"url": "hxxp://media.expedia.com/hotels/1000000/10000/5900/5900/5900_44_b.jpg",
"thumbnailUrl": "hxxp://media.expedia.com/hotels/1000000/10000/5900/5900/5900_44_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694182,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "hxxp://media.expedia.com/hotels/1000000/10000/5900/5900/5900_47_b.jpg",
"thumbnailUrl": "hxxp://media.expedia.com/hotels/1000000/10000/5900/5900/5900_47_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
}]}}';
$k = json_decode($data);
print_r($k->HotelImages->HotelImage[0]->url);
exit();