我有一个由recipeBlob = JSON.stringify(recipeData)
. 这是一个很长的字符串,但这里是它的一个示例:
"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}
我通过 $.post 这样发送:
$.post('scripts/save_blob.php', {
blob : recipeBlob
});
$string = $_POST['blob']
到达我的 PHP 脚本的显示如下:
{\"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\"}
当我运行json_decode($string)
它时返回错误 #4,这是 json 语法错误。
我不知道角色在过程的哪个部分被转义,我需要避免。