php json_encode & jquery parseJSON single quote issue

后端 未结 5 2054
庸人自扰
庸人自扰 2020-12-24 01:40

I searched and read most of the related topics, but they weren\'t what I was looking for.

I\'ve a JSON enocded string with json_encode PHP function:

5条回答
  •  一个人的身影
    2020-12-24 02:00

    However when I make a change in JSON encoded string - adding Backslash to single quote

    That escapes it in the PHP string literal. It is then inserted into the PHP string as a simple '.

    If you want to escape it before inserting it into JavaScript then you need to add slashes to the string you get out of json_encode (or rather, since you aren't using that (you should be!) the JSON string you build by hand).

    That is more work then you need though. The real solution is to remember that JSON is a subset of JavaScript literal syntax:

    var obj = ;
    

提交回复
热议问题