I just thought I should quickly post this note simply because I know a few people might have problems with parsing it with the above functions.

I would like first to say that jsonencode and jsondecode are PHP 5.2.0+ methods of parsing and dealing with Javascript Simple Object Notation. basically looks a bit like this {"key":"value"}. The idea is to be able to do useful things with objects like these and stepping through the key and value pairs while doing something with them.

The problem however is you sometimes get JSON sent as a string through an HTTP method like $POST and the quotes in there are automatically (well in my case). escaped with backslashes like this {"jsonkey":"jsonvalue"}. Before you actually call jsondecode on your json data use the built in stripslashes function first. so your code should look like this in one line

$jsonarray = jsondecode(stripslashes($jsonObject));

hope this helps someone.

Tags: