Skip to content
Advertisement

json_decode returns error #4 in PHP

When trying to parse the below json string with json_decode() in PHP 5.3 I get error #4 returned which translates to JSON_ERROR_CTRL_CHAR. Also jsonlint gives me a syntax error: Expecting '{', '[' when manually validating.

How can I reformat this string so it can be parsed?

a:1:{s:18:"test";s:55:"test.pdf";} 

Advertisement

Answer

That’s a PHP serialized string, not a JSON. You may use unserialize to parse it.

Another thing, the function json_code() doesn’t exist, you may be talking about the function json_decode() which transform a json string into a php array

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement