【请教】商品列表保存在json文件中,如何在python中读取文件中并保存到字典中

需求:

商品列表保存到文件中,通过脚本读取修改。
**多谢各位支持**

商品清单{test1.json}:

{"iphone":{"5999":{"美国公司生产":"价格贵,性能好"}},"哇哈哈":{"15":{"中国":"好喝不贵,都喜欢"},},"ThinkPad X1":{"9999":{"联想公司产品":"价格贵,超极本,适合办公"}},"矿泉水":{"2":{"山区山泉水":"解渴,矿物质含量高,人体必需"}}}
{"iphone":{"5999":{"美国公司生产":"价格贵,性能好"}},"哇哈哈":{"15":{"中国":"好喝不贵,都喜欢"},},"ThinkPad X1":{"9999":{"联想公司产品":"价格贵,超极本,适合办公"}},"矿泉水":{"2":{"山区山泉水":"解渴,矿物质含量高,人体必需"}}}

python脚本内容:

import json

with open('test1.json', "r", encoding='utf-8-sig') as T:
    list01 = T.read()
    list02 = list01.replace('\n','')
    list03 = list02.replace("\'",'\"').replace(' ','')
    dict01 = json.loads(list03, encoding='utf-8-sig') 
  
print(dict01)

报错内容如下:

posted @ 2021-06-23 21:47  酱香牛肉  阅读(160)  评论(0编辑  收藏  举报