How to decode an invalid json string in python

后端 未结 4 1440
自闭症患者
自闭症患者 2020-12-18 03:57

I wonder if there is a way to decode a JSON-like string.

I got string:

\'{ hotel: { id: \"123\", name: \"hotel_name\"} }\'

It\'s no

4条回答
  •  抹茶落季
    2020-12-18 04:50

    Use demjson module, which has ability to decode in non-strict mode.

    In [1]: import demjson
    In [2]: demjson.decode('{ hotel: { id: "123", name: "hotel_name"} }')
    Out[2]: {u'hotel': {u'id': u'123', u'name': u'hotel_name'}}
    

提交回复
热议问题