This document is for Kombu's development version, which can be
significantly different from previous releases. Get the stable docs here:
5.0.
JSON实用程序- kombu.utils.json
JSON序列化实用程序。
-
class kombu.utils.json.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[源代码]
Kombu定制JSON编码器。
-
default(o)[源代码]
在子类中实现此方法,以便它返回 o
,或调用基实现(引发 TypeError
)。
例如,要支持任意迭代器,可以实现如下默认设置::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return JSONEncoder.default(self, o)
-
kombu.utils.json.dumps(s, _dumps=<function dumps>, cls=<class 'kombu.utils.json.JSONEncoder'>, default_kwargs=None, **kwargs)[源代码]
将对象序列化为json字符串。
-
kombu.utils.json.loads(s, _loads=<function loads>, decode_bytes=True, object_hook=<function object_hook>)[源代码]
从字符串反序列化json。
-
kombu.utils.json.object_hook(o: dict)[源代码]
钩子函数来执行自定义反序列化。
-
kombu.utils.json.register_type(t: type[T], marker: str, encoder: Callable[[T], EncodedT], decoder: Callable[[EncodedT], T])[源代码]
添加对序列化/反序列化本机Python类型的支持。