本文介绍了对php对象的卷曲响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发出这个卷曲请求:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "affiliate-feeds.snapdeal.com/feed/api/order?startDate=2016-01-01&endDate=2016-05-03&status=approved");
curl_setopt(
$ch, CURLOPT_HTTPHEADER,
array(
'Snapdeal-Affiliate-Id:'.$affiliateId,
'Snapdeal-Token-Id:'.$token,
'Accept:application/json'
)
);
$response = curl_exec($ch);
curl_close($ch);
// work with $response here:
$jsonData = json_decode($response);
Mage::log( $jsonData["productDetails"][0]["product"]);
响应是这样的:
{"productDetails":[{"product":"Philips QT4000 Trimmer Black","category":"Appliances","orderCode":"12569696012","quantity":1,"price":936.0,"sale":936.0,"commissionRate":1.0,"commissionEarned":9.36,"dateTime":"03/29/2016 22:49:06","affiliateSubId1":"","affiliateSubId2":"null","userType":"EXISTING","deviceType":"web"}],"nextURL":null}
log语句不打印任何内容。我在这里做错了什么?
The log statement prints nothing. What I am doing wrong here?
推荐答案
使用 curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);
卷曲并通过 json_decode()
...传递 true
。
Use curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
in your curl and pass true
with json_decode()
....
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "affiliate-feeds.snapdeal.com/feed/api/order?startDate=2016-01-01&endDate=2016-05-03&status=approved");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch, CURLOPT_HTTPHEADER,
array(
'Snapdeal-Affiliate-Id:'.$affiliateId,
'Snapdeal-Token-Id:'.$token,
'Accept:application/json'
)
);
$response = curl_exec($ch);
curl_close($ch);
// work with $response here:
$jsonData = json_decode($response,true);
Mage::log($jsonData['productDetails'][0]['product']);
这将输出:
Philips QT4000 Trimmer Black
这篇关于对php对象的卷曲响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!