-
(转)Python JSON序列化
- import json
-
- d=dict(name="cui",age=20,score=88)
- print json.dumps(d)
-
- l=["cui",20,88]
- print json.dumps(l)
-
- class Student(object):
-
- def __init__(self):
- super(Student, self).__init__()
- self.age=20
- self.name="cui"
- self.score=88
-
- print json.dumps(Student(),default=lambda obj:obj.__dict__)
-
- json_str='{"age": 20, "score": 88, "name": "cui"}'
- d= json.loads(json_str)
- print d
-
- json_str='["cui", 20, 88]'
- l=json.loads(json_str)
- print l
-
- json_str='{"age": 20, "score": 88, "name": "cui"}'
- def dict2Student(d):
- s=Student()
- s.name=d["name"]
- s.age=d["age"]
- s.score=d["score"]
- return s
-
- student=json.loads(json_str,object_hook=dict2Student)
-
相关阅读:
VUE iframe消息通信postMessage
sqlserver 增加新列并加备注说明备用
实用的apipost 软件,登录token改变,其他请求也随之改变自带token请求设置
介绍一下magic.net多租户的应用
vue 给路由增加自定义信息meta属性
hyperv 设置NAT网络备忘
mybatis plus 多字段排序
c#使用redis
centos ssh连接卡在【To escape to local shell, press 'Ctrl+Alt+]'.】的解决方法
java stream 转字符串数组
-
原文地址:https://www.cnblogs.com/liguangxu/p/5506990.html
Copyright © 2020-2023
润新知