所以我有一个名为 $ subcats 的数组,如下所示:
Array
(
[83] => Array
(
[0] => Array
(
[id_sous_categ] => 4
[val] => filtre a essance
)
[1] => Array
(
[id_sous_categ] => 6
[val] => filtre AIR
)
)
[89] => Array
(
[0] => Array
(
[id_sous_categ] => 8
[val] => plaquette de frein
)
[1] => Array
(
[id_sous_categ] => 9
[val] => disque de frien
)
)
)
当我这样做时: $ jsonSubCats = json_encode($ subcats); 结果是空的..我做错了什么?
编辑:var_dump($ subcats)显示:
array(7) { [83]=> array(4) { [0]=> array(2) { ["id_sous_categ"]=> string(1) "4" ["val"]=> string(16) "filtre a essance" } [1]=> array(2) { ["id_sous_categ"]=> string(1) "6" ["val"]=> string(10) "filtre AIR" } [2]=> array(2) { ["id_sous_categ"]=> string(1) "7" ["val"]=> string(14) "filtre a huile" } [3]=> array(2) { ["id_sous_categ"]=> string(2) "14" ["val"]=> string(16) "filtre a gasoile" } } [89]=> array(2) { [0]=> array(2) { ["id_sous_categ"]=> string(1) "8" ["val"]=> string(19) "plaquette de frein " } [1]=> array(2) { ["id_sous_categ"]=> string(1) "9" ["val"]=> string(15) "disque de frien" } } [84]=> array(6) { [0]=> array(2) { ["id_sous_categ"]=> string(2) "10" ["val"]=> string(23) "huile SAE 50 5L 5000 km" } [1]=> array(2) { ["id_sous_categ"]=> string(2) "11" ["val"]=> string(23) "huile SAE 50 1L 5000 km" } [2]=> array(2) { ["id_sous_categ"]=> string(2) "12" ["val"]=> string(22) "huile 15W40 5L 7000 km" } [3]=> array(2) { ["id_sous_categ"]=> string(2) "13" ["val"]=> string(22) "huile 15w40 1L 7000 km" } [4]=> array(2) { ["id_sous_categ"]=> string(2) "15" ["val"]=> string(22) "huile 10W40 5L10000 km" } [5]=> array(2) { ["id_sous_categ"]=> string(2) "16" ["val"]=> string(22) "huile 10W40 1L10000 km" } } [91]=> array(3) { [0]=> array(2) { ["id_sous_categ"]=> string(2) "17" ["val"]=> string(13) "joint culasse" } [1]=> array(2) { ["id_sous_categ"]=> string(2) "18" ["val"]=> string(20) "joint cache soupape " } [2]=> array(2) { ["id_sous_categ"]=> string(2) "19" ["val"]=> string(13) "joint carter " } } [86]=> array(6) { [0]=> array(2) { ["id_sous_categ"]=> string(2) "20" ["val"]=> string(6) "avant " } [1]=> array(2) { ["id_sous_categ"]=> string(2) "21" ["val"]=> string(7) "arrier " } [2]=> array(2) { ["id_sous_categ"]=> string(2) "22" ["val"]=> string(18) "amortisseur avant " } [3]=> array(2) { ["id_sous_categ"]=> string(2) "23" ["val"]=> string(18) "amortisseur arrier" } [4]=> array(2) { ["id_sous_categ"]=> string(2) "24" ["val"]=> string(28) "biellette suspension arriere" } [5]=> array(2) { ["id_sous_categ"]=> string(2) "25" ["val"]=> string(26) "biellette suspension avant" } } [96]=> array(1) { [0]=> array(2) { ["id_sous_categ"]=> string(2) "26" ["val"]=> string(6) "moteur" } } [80]=> array(1) { [0]=> array(2) { ["id_sous_categ"]=> string(2) "27" ["val"]=> string(15) "but�e embrayage" } } }
提前致谢。
答案 0 :(得分:2)
json_encode
无法编码非utf8字符串。检查字符串编码。如果是这种情况,您必须将字符串转换为utf8或使用您自己的json_encode
实现(您可以通过短语&#34快速谷歌; php json_encode实现")。
答案 1 :(得分:0)
确保在服务器中启用了json支持。
在任何php文件中运行简单<?php phpinfo() ?>
并搜索 JSON 。