Mahamadali Mahamadali - 3 months ago 9
PHP Question

json_decode not working in php

Please check my below code and please let me know ehat wrong I am doing , I just want to decode the json and print on the browser as array

<?php

$json = '{
"Token" : "xxx-xxx-xxx",
"ID": "1",
"Recipients": [
{
"Recipient_ID": "XX",
"From_Name": "XXX",
"From_Email": "XXX",
"To_Name": "XXX",
"To_Email": "XXX",
"Subject": "XXX",
"Message": "XXX",
"Attachments": [
{
"File_Name": "XXX",
"File_Path": "XXX",
}
],
}
],
}';

$input = $json;
print_r(json_decode(stripslashes($input)));

?>


I tried this json string to decode online (http://jsonviewer.stack.hu/) and its working fine so no issue with json string. Any help would be appreciate.

Answer
<?php

$json = '{
    "Token": "xxx-xxx-xxx",
    "ID": "1",
    "Recipients": [{
        "Recipient_ID": "XX",
        "From_Name": "XXX",
        "From_Email": "XXX",
        "To_Name": "XXX",
        "To_Email": "XXX",
        "Subject": "XXX",
        "Message": "XXX",
        "Attachments": [{
            "File_Name": "XXX",
            "File_Path": "XXX"
        }]
    }]
}';

$input = $json;
var_dump(json_decode(stripslashes($input)));

?>
Comments