import json
#json dumps to List
books =[
{
'username':"張三",
'age':18,
'country':'china'
},
{
'username':"李四",
'age':21,
'country':'Taiwan'
}
]
json_Str = json.dumps(books)
print("json_格式: " + str(type(json_Str)))
print(json_Str)
#json dump to file.json
# encoding=’utf-8′ and ensure_ascii=False
with open(‘test_json.json’,'w+’,encoding=’utf-8′) as fp:
#fp.write(json_Str)
json.dump(books,fp,ensure_ascii=False)