json.dumps(): escaping forward slashes

前端 未结 2 897
眼角桃花
眼角桃花 2021-01-02 15:56

Since forward slashes can only occur in strings inside a JSON serialized object and are not escaped (in the default settings), using

json.dump(some_dict).re         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 16:03

    Use escape_forward_slashes as per ujson doc,

    escape_forward_slashes Controls whether forward slashes (/) are escaped. Default is True:

    >>> ujson.dumps("http://esn.me")
    '"http:\/\/esn.me"'
    >>> ujson.dumps("http://esn.me", escape_forward_slashes=False)
    '"http://esn.me"'
    

    See here.

提交回复
热议问题