当前位置:Gxlcms > PHP教程 > php多条json转换为数组解决思路

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

时间:2021-07-01 10:21:17 帮助过:13人阅读

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
[{"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));
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] => 河北省
)

)

------解决方案--------------------
$str = <<[{"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));

人气教程排行