配置usjon将datetime作为datetime对象而不是int utc timestamp返回

时间:2014-09-03 05:36:24

标签: python json datetime

ujson将python datetime对象转储为UTC时间戳(int值)。是否可以为ujson配置自定义编码器以将日期时间转换为isoformat中的sting?

由于

2 个答案:

答案 0 :(得分:1)

要在json序列化之前扩展Daria的将datetime对象转换为ISO格式字符串的解决方案,您可以编写一个包装器,负责在加载json数据时将日期转换回datetime对象。

答案 1 :(得分:0)

看起来ujson不允许这样做。 ujson只接受3种编码选项:encode_html_charsensure_asciidouble_precision

可以使用其他lib,例如simplejson,但看起来ujson是最快的。

解决方案:在json序列化之前将python datetime对象转换为ISO格式的字符串。

相关问题