第1关:JSON篇:JSON基础知识
{
"count":3,
"students":
[
{"name" : "赵昊" , "age" : 15 , "ismale" : true},
{"name" : "龙傲天" , "age" : 16 , "ismale" : true},
{"name" : "玛丽苏" , "age" : 15 , "ismale" : false}
]
}
第2关:JSON篇:使用json库
import json
def Func():
data = open("step2/2017.txt","r",encoding = "utf-8")
obj = json.load(data)
data.close()
#********** Begin *********#
obj={
"count":4,
"infos":
[
{"name":"赵昊" , "age":16 ,"height": 1.83, "sex" : "男性" },
{"name":"龙傲天" , "age":17 ,"height": 2.00, "sex" : "男性"},
{"name":"玛丽苏" , "age":16 ,"height": 1.78, "sex" : "女性"},
{"name":"叶良辰" , "age":17 ,"height": 1.87, "sex" : "男性"}
]
}
#********** End **********#
output = open("step2/2018.txt","w",encoding = "utf-8")
json.dump(obj,output) #输出到文件
output.close()