json,python对象转成json
persons = [{'username':"张三",'age': 18,'country': 'china'},{'username': '李赛','age': 20,'country': 'china'}]json_str = json.dumps(persons)with open('person.json','w',encoding='utf-8') as fp:json.dump(persons,fp,ensure_ascii=False)
读取json
json_str = '[{"username": "张三", "age": 18, "country": "china"}, {"username": "李赛", "age": 20, "country": "china"}]'persons = json.loads(json_str)
with open('person.json','r',encoding='utf-8') as fp:persons = json.load(fp)
