Python json.loads fails with `ValueError: Invalid control character at: line 1 column 33 (char 33)`

后端 未结 5 1427
时光取名叫无心
时光取名叫无心 2020-11-27 05:02

I have a string like this:

s = u\"\"\"{\"desc\": \"\\u73cd\\u54c1\\u7f51-\\u5168\\u7403\\u6f6e\\u6d41\\u5962\\u54c1\\u7f51\\u7edc\\u96f6\\u552e\\u5546 
5条回答
  •  鱼传尺愫
    2020-11-27 05:22

    Another option, perhaps, is to use the strict=False argument

    According to http://docs.python.org/2/library/json.html

    "If strict is False (True is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'."

    For example:

    json.loads(json_str, strict=False)
    

提交回复
热议问题