'''
    json: 数据存储的一种格式
    {'':'','':''}
    {
        '':{
            {'':''},
            {'':''},
            {'':''},
        }
    }
    python类型    JSON 类型
    dict          object
    list,tuple     arroy
    str            string
    数值            number
    True,False      true,false
    Nobe            null
    四个方法
    json.dump()     将python数据类型转换并保存到JSON格式的文件内
    json.dumps()    将python数据类型转换为JSON格式的字符串
    json.load()     从JSON格式的文件内读取,并转换为python类型
    json.loads()    将JSON格式的字符串转换为python类型
'''
import json
import pygame
person = {'name':'kehao','age':14,'tel':['17688888888','18622222222'],'happy':True}
print(person,type(person))
# # 转换为JSON    sort_keys 排序 默认False
jsonStr = json.dumps(person,indent=4,sort_keys=True)
print(jsonStr)
#  indent  首行缩进
json.dump(person,open('data.json','w'),indent=4)
# 将json string 转换成 python对象
pythonObj = json.loads(jsonStr)
print(pythonObj)
pythonObj = json.load(open('data.json','r'))
print(pythonObj)