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":"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]}]}
share|improve this question
can you add more of your code? – experimentX Mar 9 '11 at 11:09
What does var_dump($responce) output? – Jon Mar 9 '11 at 11:14
do you get your data from a database? – thedev Mar 9 '11 at 11:22
1  
Should we guess at your code? – Lightness Races in Orbit Mar 9 '11 at 11:26

1 Answer

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

share|improve this answer

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.