首頁 > 後端開發 > php教程 > php 多条json 转换为数组解决思路

php 多条json 转换为数组解决思路

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-13 11:51:59
原創
1067 人瀏覽過

php 多条json 转换为数组
{"SchemeName":"湖田窑遗址(葫芦窑、马蹄窑)本体保护工程设计方案","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"江西省"},{"SchemeName":"元中都遗址宫城南门、西南角台夯土保护工程","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"},{"SchemeName":"元中都遗址环境整治工程","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"},{"SchemeName":"内丘邢窑遗址保护大棚","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"}



怎么转换为数组
------解决方案--------------------
加对中括号
注意编码要是 utf-8的

$s =<<< TXT<br />[{"SchemeName":"湖田窑遗址(葫芦窑、马蹄窑)本体保护工程设计方案","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"江西省"},{"SchemeName":"元中都遗址宫城南门、西南角台夯土保护工程","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"},{"SchemeName":"元中都遗址环境整治工程","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"},{"SchemeName":"内丘邢窑遗址保护大棚","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"}]<br />TXT;<br /><br />print_r(json_decode($s, 1));
登入後複製
Array<br />(<br />    [0] => Array<br />        (<br />            [SchemeName] => 湖田窑遗址(葫芦窑、马蹄窑)本体保护工程设计方案<br />            [SchemeType] => 技术方案(委托第三方)<br />            [DeclareYear] => 2014<br />            [SchemeStatus] => 评审中<br />            [Province] => 江西省<br />        )<br /><br />    [1] => Array<br />        (<br />            [SchemeName] => 元中都遗址宫城南门、西南角台夯土保护工程<br />            [SchemeType] => 技术方案(委托第三方)<br />            [DeclareYear] => 2014<br />            [SchemeStatus] => 评审中<br />            [Province] => 河北省<br />        )<br /><br />    [2] => Array<br />        (<br />            [SchemeName] => 元中都遗址环境整治工程<br />            [SchemeType] => 技术方案(委托第三方)<br />            [DeclareYear] => 2014<br />            [SchemeStatus] => 评审中<br />            [Province] => 河北省<br />        )<br /><br />    [3] => Array<br />        (<br />            [SchemeName] => 内丘邢窑遗址保护大棚<br />            [SchemeType] => 技术方案(委托第三方)<br />            [DeclareYear] => 2014<br />            [SchemeStatus] => 评审中<br />            [Province] => 河北省<br />        )<br /><br />)<br />
登入後複製

------解决方案--------------------
$str = <<<phps<br />[{"SchemeName":"湖田窑遗址(葫芦窑、马蹄窑)本体保护工程设计方案","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"江西省"},{"SchemeName":"元中都遗址宫城南门、西南角台夯土保护工程","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"},{"SchemeName":"元中都遗址环境整治工程","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"},{"SchemeName":"内丘邢窑遗址保护大棚","SchemeType":"技术方案(委托第三方)","DeclareYear":"2014","SchemeStatus":"评审中","Province":"河北省"}]<br />phps;<br />var_dump(json_decode($str,true));
登入後複製

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
javascript - js正規符合特定字串
來自於 1970-01-01 08:00:00
0
0
0
為什麼說非物件呼叫成員函數fetch()
來自於 1970-01-01 08:00:00
0
0
0
資料庫設定檔必須要用二維數組
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板