在我的代码中,我构建了一个数组并使用json_encode对其进行编码,除非我在编码前插入指令"echo $responce->rows;“,否则json_encode将为此数组返回null;,如果我注释掉此行,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]}]}发布于 2011-03-09 19:17:12
如果您的数组值没有编码为utf8 (因此它们对于json_encode是不安全的),那么您将得到json_encode返回的null。
如果您从数据库获取数据,请尝试使用:
SELECT语句前的mysql_query('SET CHARACTER SET utf8')
https://stackoverflow.com/questions/5244872
复制相似问题