适合于用bottlepy开发的restapi的json序列化程序
bottle-rest-serializer的Python项目详细描述
瓶托序列化程序
使用BottlePy
构建的restapi的简单序列化程序当dicts/对象包含datetime
或Decimal
实例时,默认的python序列化程序不工作。这个插件是为了解决这个“问题”。
datetime
实例将转换为ISO8601 strings。Decimal
实例将转换为float
。
安装
bottle-rest-serializer
可从pypi获得bottle-rest-serializer
:
pip install bottle-rest-serializer
json序列化程序:
fromdatetimeimportdatetimefromdecimalimportDecimalfrombottleimportBottle,runfromtruckpad.bottle.rest_serializerimportFlexibleJSONPluginapp=Bottle()app.install(FlexibleJSONPlugin())@app.get('/')defindex():return{'now':datetime.now(),'float_number':Decimal(123.4567),'int_number':Decimal(4567)}if__name__=='__main__':run(app)
xml序列化程序:
未来开发:p