我的json是
{"productInfoList":[{"prod":"Some Products","price":"someprice"},{"prod":"Another Product","price":"48"}]}
我的php代码是
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/file.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$voo = curl_exec($ch);
curl_close($ch);
$yf= json_decode($voo,true);
for ($i=0; $i < 5; $i++)
{
$fkname = $yf->{'productInfoList'}[$i]->{'prod'};
echo $i;
echo $fkname;
}
?>
输出结果是012345
。如何使用json获取产品名称?我已经通过http://jsonviewer.stack.hu/检查了json文件,一切都很好。
i++
,请在运行之前编辑它。 - Luthando Ntsekwa