如何在serializer中使用鱼书重构的jsonencode
来源:9-1 小程序演示API调用效果

Linx
2019-12-17
老师,请问如上怎么实现,我就看到要替换的话,需要在serializer初始化时传入cls参数,但是失败了
是这样的,我使用TimedJSONWebSignatureSerializer.dumps来加密一个字典,但是字典里包含一个datetime变量,直接s.dumps失败。我看到名字含JSON,思考会不会和jsonencode有关系,查看源码,发现flask的json的__init__里有这么一段注视
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``.default()`` method to serialize additional types), specify it with
the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.
然后我尝试了几个方式,都不成功,重构的jsonencode不就是To use a custom ``JSONEncoder`` subclass
请问老师要怎么传入cls才能使用custom ``JSONEncoder``
2回答
-
Linx
提问者
2019-12-24
原来这个很简单,就是初始化的时候,传入flask的json
from flask import json
from itsdangerous import TimedJSONWebSignatureSerializer
s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY'], serializer=json)
这就可以了
10 -
7七月
2019-12-18
麻烦详细一些描述
012019-12-18
相似问题