根据以下字段:
url ="blewpass.com"
ssl = "yes"
tags = [{'html':'hi'},{'title':'My first page'},{'h2':'My First Line'},{'p':'Hey'},{'h2':'My Second Line'}]
我想将这些字段转换成JSON格式并将其存储在JSON文件中。我不能将标签转换为单个字典,因为键不能保存多个值。我想把这些字段直接转换成JSON吗?如何从这些领域创建一个妥善管理的json数据格式?
如果您只想将所有字段写入json文件,
试
import json
url ="blewpass.com"
ssl = "yes"
tags = [{'html':'hi'},{'title':'My first page'},{'h2':'My First Line'},{'p':'Hey'},{'h2':'My Second Line'}]
temp_json = tags
temp_json.insert(0,({"url":url,"ssl":ssl}))
file = open("filename.json",'w')
json.dump(temp_json,file)