python json dumps

前端 未结 4 1010
予麋鹿
予麋鹿 2020-12-15 17:46

i have the following string, need to turn it into a list without u\'\':

my_str = \"[{u\'name\': u\'squats\', u\'wrs\': [[u\'99\', 8]], u\'id\': 2}]\"
         


        
4条回答
  •  粉色の甜心
    2020-12-15 18:07

    >>> "[{\"id\": 2, \"name\": \"squats\", \"wrs\": [[\"55\", 9]]}]".replace('\\"',"\"")
    '[{"id": 2, "name": "squats", "wrs": [["55", 9]]}]'
    

    note that you could just do this on the original string

    >>> "[{u'name': u'squats', u'wrs': [[u'99', 8]], u'id': 2}]".replace("u\'","\'")
    "[{'name': 'squats', 'wrs': [['99', 8]], 'id': 2}]"
    

提交回复
热议问题