PHP: json_decode not working

some time there is issue of html entities, for example \" it will represent like this \&quot, so you must need to parse the html entites to real text, that you can do using html_entity_decode() method of php.

$jsonData = stripslashes(html_entity_decode($jsonData));

$k=json_decode($jsonData,true);

print_r($k);

Most likely you need to strip off the padding from your decrypted data. There are 124 visible characters in your string but var_dump reports 144. Which means 20 characters of padding needs to be removed (a series of "\0" bytes at the end of your string).

Probably that's 4 "\0" bytes at the end of a block + an empty 16-bytes block (to mark the end of the data).

How are you currently decrypting/encrypting your string?

Edit:

You need to add this to trim the zero bytes at the end of the string:

$jsonData = rtrim($jsonData, "\0");

You have to use preg_replace for avoiding the null results from json_decode

here is the example code

$json_string = stripslashes(html_entity_decode($json_string));
$bookingdata =  json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $json_string), true ); 

Tags:

Php

Json