I\'m passing a JSON-encoded string to json_decode() and am expecting its output to be an object type, but am getting a string type instead. How can I return an
Instead of writing on the JSON array, try putting it into a PHP array first.
1,
'b' => 2,
'c' => 3,
'd' => 4,
'e' => 5
);
//Then json_encode()
$json = json_encode($array);
echo $json;
die;
?>
In you case, you are using ajax. So when you get a success, you can do this:
$.ajax({
url: 'example.com',
data: {
},
success: function(data) {
console.log(data);
}
});
Where after data inside console.log() can add the json var like data.a, data.b...
Also, with the string you providedm you do not need to json_encode since it is alrady in json format