I have a string created by recipeBlob = JSON.stringify(recipeData)
. It is a long string but here is a sample of it:
"properties":{"Energy":{"val":90.6,"unit":"cal","rdi":"2000"},"Protein":{"val":0.4,"unit":"g","rdi":"50.00000000"},"Fat":{"val":0.6,"unit":"g","rdi":"65.000000000"},"Carbohydrates":{"val":23.3,"unit":"g","rdi":"300.0000000"},"Dietary Fiber":{"val":4.1,"unit":"g","rdi":"25"},"Sugars":{"val":18.8,"unit":"g","rdi":null}
which I send via $.post like this:
$.post('scripts/save_blob.php', {
blob : recipeBlob
});
The $string = $_POST['blob']
that arrives at my PHP script is showing up like this:
{\"properties\":{\"Energy\":{\"val\":90.6,\"unit\":\"cal\",\"rdi\":\"2000\"},\"Protein\":{\"val\":0.4,\"unit\":\"g\",\"rdi\":\"50.00000000\"},\"Fat\":{\"val\":0.6,\"unit\":\"g\",\"rdi\":\"65.000000000\"},\"Carbohydrates\":{\"val\":23.3,\"unit\":\"g\",\"rdi\":\"300.0000000\"}
When I run json_decode($string)
it is returning error #4 which is json syntax error.
I don't know at which part of the process the characters are being escaped, which I need to avoid.