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] 部分の先頭に 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 に答える