Python json.loads ValueError, expecting delimiter

后端 未结 4 1231
后悔当初
后悔当初 2020-12-24 12:53

I am extracting a postgres table as json. The output file contains lines like:

{\"data\": {\"test\": 1, \"hello\": \"I have \\\" !\"}, \"id\": 4}
         


        
4条回答
  •  [愿得一人]
    2020-12-24 13:34

    Try this:

    json.loads(r'{"data": {"test": 1, "hello": "I have \" !"}, "id": 4}')
    

    If you have that string inside a variable, then just:

    json.loads(data.replace("\\", r"\\"))
    

    Hope it helps!

提交回复
热议问题