json_encode returning null if array not accessed before
In my code I build an array and encode it using json_encode, json_encode returns null for this array unless I insert the instruction "echo $responce->rows[0][0];" before encoding, if I comment out this row json_encode returns null!
Can someone find out why?
echo $responce->rows[0][0];
echo json_encode($responce);
It has this behaviour with this encoded json, but works for different arrays:
{"rows":[{"id":"33UD","cell":["Great Yarmouth Borough Council",5875732.23,61.01]},
{"id":"41U开发者_如何学PythonE","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]}]}
You will get null
returned by json_encode
if your array values are not encoded to utf8
(so they are not safe for json_encode
)
if you get your data from a db try using:
mysql_query('SET CHARACTER SET utf8')
before your SELECT
statement
精彩评论