1-5JSON数据解析

 

 

 

 

 

 

import json

data={'id':1,'name':'51zxw','password':'66666'}
print(type(data))

json_str=json.dumps(data)
print(type(json_str))
print(json_str)
import json

json_str='{"id":1,"name":"51zxw","password":"66666"}'
print(type(json_str))

data=json.loads(json_str)
print(type(data))
print(data)

print(data['id'])
print(data['name'])

with open('data.json','w') as f:
    json.dump(data,f)

with open('data.json','r') as f:
    data=json.load(f)
    print(data)

 

posted @ 2021-03-31 20:56  牛小胖666  阅读(43)  评论(0编辑  收藏  举报