doujing5150 2013-03-12 17:38
浏览 69
已采纳

jQuery.post正在发送转义字符

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.

  • 写回答

1条回答 默认 最新

  • doulu1867 2013-03-12 18:30
    关注

    @Juhana provided the most direct answer to the question, PHP magic quotes were turned on on the server, thus automatically escaping quotes.

    @dfsq provided the solution I actually used, which is to just send the javascript object without stringifying it. it arrives to the PHP script as an array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么