CURL后的结果解析成数组问题
index.php,echo json_encode后的结果为:
{"11":{"l_id":"11","l_title":"CITS-香港观光一天游【品质纯玩】"},"12":{"l_id":"12","l_title":"test"}}
然后客户端代码(client.php)如下:
<br />$curlPost='key='.urlencode($key);<br />$ch=curl_init();<br />curl_setopt($ch,CURLOPT_URL,'http://www.cits-sz.net/api/index.php');<br />curl_setopt($ch,CURLOPT_HEADER,0);<br />curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);<br />curl_setopt($ch,CURLOPT_POST,1);<br />curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);<br />$data=curl_exec($ch);<br />curl_close($ch);<br />echo json_decode($data,true);<br />
$s = '{"11":{"l_id":"11","l_title":"CITS-香港观光一天游【品质纯玩】"},"12":{"l_id":"12","l_title":"test"}}';<br />print_r(json_decode($s,1));
Array<br />(<br /> [11] => Array<br /> (<br /> [l_id] => 11<br /> [l_title] => CITS-香港观光一天游【品质纯玩】<br /> )<br /><br /> [12] => Array<br /> (<br /> [l_id] => 12<br /> [l_title] => test<br /> )<br /><br />)<br /><br />