0

我正在创建 http_client 对象并发出 GET 请求。下面是我的代码。

$httpc = new HTTP_CLIENT();
$httpc->get("$endpointUrl?operation=getchallenge&username=$userName");
$response = $httpc->currentResponse();
print_r($response);
output: Array ( [url] => http://localhost:8888//webservice.php?operation=getchallenge&username=admin [code] => 200 [headers] => Array ( [date] => Thu, 27 Sep 2012 07:30:17 GMT [server] => Apache/2.0.52 (Win32) PHP/5.2.6 [x-powered-by] => PHP/5.2.6 [expires] => Thu, 19 Nov 1981 08:52:00 GMT [cache-control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0 [pragma] => no-cache [content-length] => 102 [connection] => close [content-type] => application/json ) [body] => {"success":true,"result":{"token":"50640089780c4","serverTime":1348731017,"expireTime":1348731317}} )

jsonResponse = Zend_JSON::decode($response['body']);

我试图从这个数组中提取“body”部分,但我得到的值是空白的。如果可以的话,请帮助我。

注意:您可以在 [body] 部分的开头看到具有 JUNK 值的输出。

4

2 回答 2

1

因为那是一个 API,而且它们显然有一些 BOM 字符,你应该提取它们并解码:

$jsonResponse = Zend_JSON::decode(substr($response['body'], 6));
于 2012-09-27T08:00:19.393 回答
0

试试这个

var_dump(Zend_Json_Decoder::decode($data, Zend_Json::TYPE_ARRAY));
于 2012-09-27T07:54:34.677 回答