创建一个比较复杂的参数的时候,将参数定义成了一个字典,然后格式化了一下,报错TypeError: unhashable type: 'list'
import json
data = {[{"max": 10000,
"min": 10000,
"terms": [
{"fundInfo":
[{"feeType": "1",
"fundId": 000,
"priority": "1",
"rate": "0",
"rateType": 1}],
"term": 6}]}]}
data1 = json.dumps(data,sort_keys=True,indent=1)
print(data1)
报错
TypeError: unhashable type: 'list'
解决方案:
将data后面的{}改成[]即可,参考文章:https://blog.csdn.net/lyq_12/article/details/81260427
修改后的代码:
import json
data = [[{"max": 10000,
"min": 10000,
"terms": [
{"fundInfo":
[{"feeType": "1",
"fundId": 000,
"priority": "1",
"rate": "0",
"rateType": 1}],
"term": 6}]}]]
data1 = json.dumps(data,sort_keys=True,indent=1)
print(data1)
python json.dumps的相关内容可参考:https://www.jianshu.com/p/cfbcd9f8691c 写的很细致
网友评论