How to escape special characters in building a JSON string?

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

Here is my string

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


        
11条回答
  •  有刺的猬
    2020-11-22 04:55

    regarding AlexB's post:

     \'  Apostrophe or single quote
     \"  Double quote
    

    escaping single quotes is only valid in single quoted json strings
    escaping double quotes is only valid in double quoted json strings

    example:

    'Bart\'s car'       -> valid
    'Bart says \"Hi\"'  -> invalid
    

提交回复
热议问题