一个api接口,接受json数据的例子
set_time_limit(0);
$ch = curl_init();
// 2. 设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, "http://www.sample.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RANGE, "0-5000");
curl_setopt($ch, CURLOPT_NOPROGRESS, FALSE);
// 3. 执行并获取HTML文档内容
$output = curl_exec($ch);
// iconv('GB2312', 'UTF-8', 'magento论坛');
$cc = json_decode($output);
//$cc = iconv('GB2312', 'UTF-8', $cc);
//var_dump($cc);
$jj =1;
$sql="";
foreach($cc as $aa){
//echo $aa['customer']."<br/>";
foreach($aa as $dd=>$bb){
}
}
然后就可以对接受过来的数据进行处理了!