I have the fallowing string in php:
$code = "[[],["Mon","01"," 1.7"," 8","3"," 96","33","
29.01.2013"],["Tue","01"," 0.3"," 24","2","100","16","
30.01.2013"],["Wed","01"," 5.4"," 28","2"," 98","5","
31.01.2013"],["Thu","01"," 8.7"," 22","3"," 92","23","
01.02.2013"],["Fri","01"," 5.1"," 43","3"," 91","22","
02.02.2013"],["Sat","01"," 2.8"," 18","2"," 90","22","
03.02.2013"],["Sun","01"," 2.1"," 31","6"," 93","34","
04.02.2013"]]";
Now i try to decode this string with json_decode. But the result ist this one:
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
The code to output is this:
$code = json_decode($code);
print_r($code);
Why this dont work ? THis is the first time i have problems with json_decode …
Assuming that the contents of
$codeare all in a string (and not a php array like the syntax is now), the error is the fact that you have newlines inside of the strings.Notice how there is an open quote at the end of the line .. that makes for invalid JSON.
If you get rid of all of the newlines, it actually does work. Here’s my proof: