在我的代码中,我构建了一个数组并使用json_encode对其进行编码,json_encode为此数组返回null,除非我插入指令“echo $ responce-> rows [0] [0];”在编码之前,如果我注释掉这一行,json_encode会返回null!
谁能找出原因?
echo $responce->rows[0][0];
echo json_encode($responce);
它使用此编码的json具有此行为,但适用于不同的数组:
{"rows":[{"id":"33UD","cell":["Great Yarmouth Borough Council",5875732.23,61.01]},
{"id":"41UE","cell":["Newcastle-Under-Lyme District Council",2514111.76,20.24]},
{"id":"36UF","cell":["Ryedale District Council",96439.18,1.8]},{"id":"00CM","cell":
["Sunderland City Council",16473262.71,58.48]}]}
1 回答
如果您的数组值未编码为
utf8
,则json_encode
将返回null
(因此它们对json_encode
不安全)如果从db获取数据,请尝试使用:
在
SELECT
陈述之前mysql_query('SET CHARACTER SET utf8')