demjson

作者: lilith买买买 | 来源:发表于2018-05-14 10:56 被阅读45次

s = "{ip:'0.0.0.0',address:'xxxxxxxx'}"

想把类似上面这种字符串转成dict,用json.loads(s)会报错ValueError: Expecting property name: line 1 column 2 (char 1)
因为json 标准语法中必须是用双引号分别把键/值对引起来。
但是用demjson就可以啦

demjson.decode(s)
Out[1]: {u'address': u'xxxxxxxx', u'ip': u'0.0.0.0'}

相关文章

网友评论

      本文标题:demjson

      本文链接:https://www.haomeiwen.com/subject/bteddftx.html