How to escape special characters in building a JSON string?

后端 未结 11 979
北恋
北恋 2020-11-22 04:18

Here is my string

{
    \'user\': {
        \'name\': \'abc\',
        \'fx\': {
            \'message\': {
                \'color\': \'red\'
            }         


        
11条回答
  •  执笔经年
    2020-11-22 04:51

    To allow single quotes within doubule quoted string for the purpose of json, you double the single quote. {"X": "What's the question"} ==> {"X": "What''s the question"}

    https://codereview.stackexchange.com/questions/69266/json-conversion-to-single-quotes

    The \' sequence is invalid.

提交回复
热议问题