python3 JSON对象的学习

import json
name = {
'alex':[22,'M'],
'tony':[21,'F'],
}

name_after = json.dumps(name)
name_after = name_after.encode("utf-8") #区别于Python2
f = open("data_to_qq.txt","wb")
f.write(name_after)
f.close()

--------------------------------------------------------------------
读出数据
import json
f = open("data_to_qq.txt",'rb')

name = json.loads(f.read().decode("utf-8"))
f.close()
print(name['alex'])
print(type(name))
 
posted @ 2017-01-08 14:09  tonyklose1984  阅读(312)  评论(0编辑  收藏  举报