I’n having this problem with a json string which I’n generating with json_encode.
This is the input:
stdClass Object
(
[titles] => stdClass Object
(
[nl] => test
[en] => test
)
[contents] => stdClass Object
(
[nl] => <p>\n test</p>\n
[en] => <p>\n test</p>\n
)
[languages] => stdClass Object
(
[0] => nl
[1] => en
)
)
and I put this in my database using this SQL statement:
INSERT INTO `pages`
(`title`, `content`, `lang`)
VALUES('{"nl":"test","en":"test"}', '{"nl":"<p>\\n\ttest<\/p>\\n","en":"<p>\\n\ttest<\/p>\\n"}', '{"0":"nl","1":"en"}')
As far as I can see, nothing wrong, it’s all stored in the database, no problems.
Then I try to get the output I get this for my content:
{"nl":"<p>n test</p>n","en":"<p>n test</p>n"}
which results in:
(
[id] => 10
[title] => stdClass Object
(
[nl] => test
[en] => test
)
[content] =>
[lang] => stdClass Object
(
[0] => nl
[1] => en
)
[created] => 2012-10-24 11:49:52
)
So, my json string is invalid.
How is this possible?
I really have no idea what I’ve done wrong.
Ah! You’re right! Stupid of me not to think of that, I always use a function for my
SELECTstatements, in this code I was usingstripslashes()which apparently was making my json string invalid because there were some\nthings in it.Thank you!