html tool

2023年9月13日星期三

转:python中json中单引号引起的TypeError: expected string or buffer 解决

 参考:https://www.cnblogs.com/pinpin/p/10619471.html

import json

data = [{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5}]
print(type(data),data)

执行结果:

<class 'list'> [{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}]

但是了,json是不支持单引号的。可以用下面的方法转换

json_string=json.dumps(s)

python_obj=json.loads(json_string)

没有评论:

发表评论