需要代码演示HTTP GET请求以获取一些JSON,解码它,并迭代顶级对象,假设格式为:
[{},{},{},...]
答案 0 :(得分:0)
$url='http://api.example.com/';
$url.='?id='.urlencode($id);//append id as get
$url.='category='.urlencode($category);//append category as get
$response=file_get_contents($url);
//suppose api response is as ['name','created_at','category','id','other_data'];
$data=json_decode($response);
foreach ($data as $key => $value) {
//do your stuff
}