将文件导入到json密钥中

我希望我的程序进入一个文件,将所有行放入一个json键中。

代码:

def import_proxies():
    global proxies_json
    proxies_json = {'http': {}}
    with open("proxies.txt", 'r', encoding='utf8') as proxy_file:
        for line in proxy_file:
            val = line.split()
            proxies_json[['http'][val]] = val
            print(proxies_json)


import_proxies()

My erorr: TypeError: list indices must be integers or slices, not list

我希望它做的是将文件行作为http密钥(proxies_json = {'http': {}} )中的值导入

转载请注明出处:http://www.fuqingkongyaji.com/article/20230526/2200804.html