Escaping single quotes JSON

后端 未结 1 1728
我寻月下人不归
我寻月下人不归 2021-01-06 11:21

I am using the json module to convert a series of dictionaries to json but I am not sure why when dumping to json the strings that contain a single quote (e.g: My father\'s

相关标签:
1条回答
  • 2021-01-06 11:46

    You probably see the value representation from python interpreter. If you print the value or store it in a file, you'll see the correct behaviour.

    >>> import json
    >>> json.dumps("a'b")
    '"a\'b"'
    >>> print json.dumps("a'b")
    "a'b"
    
    0 讨论(0)
提交回复
热议问题