CURL后的结果解析成数组有关问题

WBOY
Release: 2016-06-13 11:57:06
Original
840 people have browsed it

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 />
Copy after login

得到的结果也是
{"11":{"l_id":"11","l_title":"CITS-香港观光一天游【品质纯玩】"},"12":{"l_id":"12","l_title":"test"}}

请问要如何才能将其变成如下的方式呢,谢谢了
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 />

------解决方案--------------------
那你就再 json_decode 一次

$s = '{"11":{"l_id":"11","l_title":"CITS-香港观光一天游【品质纯玩】"},"12":{"l_id":"12","l_title":"test"}}';<br />print_r(json_decode($s,1));
Copy after login
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 />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template