我希望你能提供帮助。
我正在使用campaign monitors PHP包装器。
这就是呼叫返回的内容:
CS_REST_Wrapper_Result Object ( [response] => HTTP/1.1 202 Accepted Server: csw Cache-Control: private, s-maxage=0 Content-Type: application/json; charset=utf-8 P3P: CP="OTI DSP COR CUR IVD CONi OTPi OUR IND UNI STA PRE" Date: Sun, 14 Feb 2016 13:38:18 GMT X-RateLimit-Limit: 50000 X-RateLimit-Reset: 366 X-RateLimit-Remaining: 49995 Content-Length: 216 [{"MessageID":"2e992358-d320-11e5-b287-c903ee0bee99","Recipient”:”test@test.co.uk”,”Status":"Accepted"},{"MessageID":"2ea9d51f-d320-11e5-9c7a-edc47069cc09","Recipient":"test2@test.co.uk","Status":"Accepted"}] [http_status_code] => 202 )
我希望能够遍历“消息ID”,但[response]是一个包含标题信息的字符串?
答案 0 :(得分:0)
有点畏惧,但感谢https://stackoverflow.com/a/1445519/1076753并假设您将请求结果放在var中,这将起作用
<?php
$cc='CS_REST_Wrapper_Result Object ( [response] => HTTP/1.1 202 Accepted Server: csw Cache-Control: private, s-maxage=0 Content-Type: application/json; charset=utf-8 P3P: CP="OTI DSP COR CUR IVD CONi OTPi OUR IND UNI STA PRE" Date: Sun, 14 Feb 2016 13:38:18 GMT X-RateLimit-Limit: 50000 X-RateLimit-Reset: 366 X-RateLimit-Remaining: 49995 Content-Length: 216 [{"MessageID":"2e992358-d320-11e5-b287-c903ee0bee99","Recipient”:”test@test.co.uk”,”Status":"Accepted"},{"MessageID":"2ea9d51f-d320-11e5-9c7a-edc47069cc09","Recipient":"test2@test.co.uk","Status":"Accepted"}] [http_status_code] => 202 )';
$startsAt = strpos($cc, '[{"MessageID"');
$endsAt = strpos($cc, " [http_status_code]", $startsAt);
$result = substr($cc, $startsAt, $endsAt - $startsAt);
print_r(json_decode($result));
?>