【发布时间】:2018-03-28 14:27:48
【问题描述】:
我正在尝试从此 json 文件中获取数据,但我需要与我设置的高级自定义字段匹配的数据。
$str = file_get_contents('http://gold.explorethatstore.com/wp-content/themes/divi-ETS-child-theme/run_results_bgasc.json');
// decode JSON
$json = json_decode($str, true);
// default value
$coinPrice = "Not Available";
$vendorName = get_field('bgasc_vendor_name');
// loop the json array
foreach($json['coin'] as $value){
// check the condition
if($value['coin_name'] == $vendorName){
$coinPrice = $value['url']; // get the price
break; // exit the loop
}
}
echo $coinPrice;
【问题讨论】:
-
有时会出现问题,例如类别名称“Gold American Eagles”有一个“权重”数组,但“Gold American Buffalos”没有权重数组(1 个多级数组少)......所以这是一个问题。所有类别名称应具有相同的结构...
-
嗯嗯嗯就是这样在网站上爬的,有的结果会回来,有的分类就没有了。 PHP 不会按名称识别数组?
标签: php json wordpress woocommerce advanced-custom-fields