php 多条json 转换为数组

WBOY
Lepaskan: 2016-06-23 14:00:25
asal
1022 orang telah melayarinya

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

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

两边加上 [] 就可以用json_decode 转化为数组了

加对中括号
注意编码要是 utf-8的

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



谢谢啊  两位了 明白了

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan