Python: json load Python List

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)

本篇發表於 python。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>