python 中Dict 转 Json
来源:互联网 发布:信捷plc流程梯图编程 编辑:程序博客网 时间:2024/05/01 08:03
最近在公司需要写个小工具,运用到的python,然后需要将Dict转成Json。之前遇到转换Json失败,然后以为复杂的Entity结构,不能用Json的库Json.dump(),进行转换。自己些了一个转换函数,但是效果还是不理想,后来经过大牛点拨,说Dict都可以转换成Json。
为了防止以后踩坑,废话不多说,直接上代码:
import jsonclass Student: def __init__(self): self.name = '' self.age = 0class Course: def __init__(self): self.name = '' self.student_list = []class Parser: def __init__(self): self.course = Course() def parse(): student = Student() student.name = 'Jack' student.age = 28 student2 = Student() student.name = 'Lily' student.age = 30 course = Course() course.name = 'History' course.student_list.append(student.__dict___) // 这里注意,不应该写成course.student_list.append(student) course.student_list.append(student2.__dict__) print json.dump(course.__dict__, ensure_ascii = False) // ensure_ascii=False, 是将utf-8编码的中文正确显示
1 0
- python 中Dict 转 Json
- python json 转 dict , list
- python中json到dict转换
- python中list,str,json,dict使用
- python dict转json并保存文件
- json dict python base64
- Python中model转dict
- python dict与json转换
- python dict json读写文件
- Python中dict详解
- Python中dict详解
- Python中dict 字典
- Python中dict详解
- Python中dict详解
- Python中dict使用
- Python中dict详解
- Python中dict详解
- Python中dict详解
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
- “黑马程序员”学习java基础的第一天
- LINUX 网络协议栈实现分析-SKBUFF 的实现
- Freelancer 之潮:自由职业市场的崛起
- 如何在CentOS 6.4上安装并使用OpenVZ
- python 中Dict 转 Json
- sparse bundle adjustment 摄影测量光束法平差程序库------编译
- ASP.NET MVC 过滤器(五)
- 作为一个程序员的投资
- Linux中profile、bashrc、bash_profile之间的区别和联系
- linux常用命令
- Eclipse下建立geoserver源码工程
- uva 10878 Decode the tape(字符密码推断)
- 标准为王