我有一个 json 文件。json 文件包含一些图像的路径。我想读取 url 路径并将图像保存在我的计算机中。我能够读取 json 文件,但无法在 json 中获取 image_path 对象。我的 json 文件格式如下:
Array
(
[0] => Array
(
[product] => Array
(
[product_id] => 262
[product_name] => VD0289 CUT OUT BACK DRESS
[product_inventory] => 2
[product_price] => B
[label_name] => 15
[product_status] => A
[images] => Array
(
[0] => Array
(
[image_id] => 935
[image_path] => http://gird.com/images/thumbnails/0/400/500/VD0289_VD0289.jpg
[image_thumbnail] => http://gird.com/images/thumbnails/0/60/60/VD0289_VD0289.jpg
[image_detailed] => http://gird.com/images/detailed/0/VD0289_VD0289.jpg
[image_type] => M
)
[1] => Array
(
[image_id] => 938
[image_path] => http://gird.com/images/thumbnails/0/400/500/VD0289_VD0289_(4).jpg
[image_thumbnail] => http://gird.com/images/thumbnails/0/60/60/VD0289_VD0289_(4).jpg
[image_detailed] => http://gird.com/images/detailed/0/VD0289_VD0289_(4).jpg
[image_type] => A
)
)
[options] => Array
(
)
)
)
[1] => Array
(
[product] => Array
(
[product_id] => 263
[product_name] => Chic Chanel Inspired Dress - Blue
[product_inventory] => 1
[product_price] => O
[label_name] => 9
[product_status] => A
[images] => Array
(
[0] => Array
(
[image_id] => 939
[image_path] => http://gird.com/images/thumbnails/0/400/500/100678-Blue-1.jpg
[image_thumbnail] => http://gird.com/images/thumbnails/0/60/60/100678-Blue-1.jpg
[image_detailed] => http://gird.com/images/detailed/0/100678-Blue-1.jpg
[image_type] => M
)
[1] => Array
(
[image_id] => 942
[image_path] => http://gird.com/images/thumbnails/0/400/500/100678-Blue-4.jpg
[image_thumbnail] => http://gird.com/images/thumbnails/0/60/60/100678-Blue-4.jpg
[image_detailed] => http://gird.com/images/detailed/0/100678-Blue-4.jpg
[image_type] => A
)
..............................
如何从该文件中获取所有图像路径和 image_detailed?我的php代码是:代码是只获取第一个图片路径。
<?php
$file="dw.json";
$json= json_decode(file_get_contents($file),true);
print_r ($json[0]["product"]["images"][0]["image_path"]);
//print_r($json);
?>