2023年6月8日 星期四

[Python]Json格式的列印方式

 json本身就是許多串列,每個串列裡面有許多字典型態的資料集合,所以可以用

json1 = [{"name":"jeff","age":40,"location":"taichung"}
,{"name":"renee","age":20,"location":"taichung"}
,{"name":"molly","age":6,"location":"taichung"}]
print(type(json1))

for list1 in json1:
for key,values in list1.items():
print(key,values)

輸出

<class 'list'> name jeff age 40 location taichung name renee age 20 location taichung name molly age 6 location taichung

沒有留言: