【发布时间】:2016-03-17 20:59:09
【问题描述】:
我有一本这样的字典:
{
'cost' : cost,
'oLen' : oLen
}
我把它写到文件中,所以文件包含:
{'oLen': 32, 'cost': 2048}
稍后,我会这样做:
with open('conf.conf') as f:
config = json.loads(f.read())
print config['oLen']
得到这个:
ValueError: Expecting property name: line 1 column 2 (char 1)
如果我将 json.loads 更改为 json.dumps,我会得到:
TypeError: string indices must be integers, not str
【问题讨论】:
标签: python json file dictionary