json:python

  

import json
from pathlib import Path

pp={'a':123,'b':['bam',{'c':789}],'d':True,'m':False,'v':None}
# print(p)
# print(json.dumps(p))
# b=json.dumps(p)
# print(json.loads(b))

file='d:/bb/vbn.json'
p=Path(file)
if not p.parent.exists():
    p.parent.mkdir(parents=True)

with open(file,mode='wt') as f:
    json.dump(pp,f)

with open(file,mode='rt') as f:
    print(json.load(f))

class BB: 
def ser(self): # 自定义函数用于serialization
return 'BB'
print(json.dumps(BB().ser()))
 
{
  "person": [
    {
      "name": "zxc",
      "age": 18
    },
    {
      "name": "vbn",
      "age": 88
    },
    {
      "name": "uio",
      "age": 99
    }
  ],
  "total": 3
}

 

posted @ 2020-09-19 21:58  ascertain  阅读(85)  评论(0编辑  收藏  举报