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.

  • Wow, that is a big chunk of data. Have you tried reducing the amount of data until you don't get `null`back? You can try cutting it in half, checking both halves. Then each quarter, etc. – chiborg Dec 06 '11 at 13:22
  • Using [`json_last_error()`](http://php.net/json_last_error) I got `int(4)` which points to `JSON_ERROR_SYNTAX Syntax error`. Hope it helps – Mike B Dec 06 '11 at 13:23
  • JSONLint says you have a parse error on line 82. – alex Dec 06 '11 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. –  Dec 06 '11 at 13:24
  • 1
    Make sure line returns are escaped (I have not investigated in this is the actual issue in this case): http://stackoverflow.com/a/8353806/461813 – Treffynnon Dec 06 '11 at 13:25

2 Answers2

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.

Flukey
  • 6,445
  • 3
  • 46
  • 71
  • 1
    `$json = str_replace( '\x', '\\\x', $json );` did the trick to properly escape the hex characters. –  Dec 06 '11 at 13:44
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?

Valhallen
  • 60
  • 7