0

http://pastebin.com/Jp7WRPcz

The following JSON response returns null using json_decode()

Any ideas why it is invalid, and how can I make it valid to decode.

5
  • Wow, that is a big chunk of data. Have you tried reducing the amount of data until you don't get nullback? You can try cutting it in half, checking both halves. Then each quarter, etc. Commented Dec 6, 2011 at 13:22
  • Using json_last_error() I got int(4) which points to JSON_ERROR_SYNTAX Syntax error. Hope it helps Commented Dec 6, 2011 at 13:23
  • JSONLint says you have a parse error on line 82. Commented Dec 6, 2011 at 13:23
  • Unfortunately this is third party. I have tried replacing all the hex values, but it still fails. Will look into json_last_error() now. Commented Dec 6, 2011 at 13:24
  • 1
    Make sure line returns are escaped (I have not investigated in this is the actual issue in this case): stackoverflow.com/a/8353806/461813 Commented Dec 6, 2011 at 13:25

2 Answers 2

1

Look at http://jsonlint.com/

Accoring to JSONLint, you have the following error:

Parse error on line 82:
...            "text": "Make it easier for 
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

The error is with this in the string '\x27s'

The same again for line 92.

"Roger\x27scompanion\x3cem\x3ehelped\x3c/em\x3ehimwiththeren"

Replace them with their appropriate unicode characters or add an extra slash as one slash is escaping your string.

Sign up to request clarification or add additional context in comments.

1 Comment

$json = str_replace( '\x', '\\\x', $json ); did the trick to properly escape the hex characters.
0

from PHP.net:

NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.

perhaps that is the issue?

1 Comment

See above: "Any ideas why it is invalid". Exactly this is the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.