Skip to main content
 首页 » 编程设计

python之如何在 Python 中加速 json 解码和编码操作

2025年05月04日11mayingbao

我一直在 python 2.6 中使用 json 模块,但速度很慢。我想使用更快的实现。我见过 cjson 但似乎开发没有进行,而且 api 与 json 模块不同。我还阅读了一些关于加速 json 的方法的评论。

有什么想法吗?

请您参考如下方法:

most recent versions of simplejson比 python 2.6 内置的快得多,并且具有相同的 API。如果您希望 python 代码在未安装 simplejson 的情况下继续工作,请尝试以下操作:

try: 
    import simplejson as json 
except ImportError: 
    import json 

另见:

http://bugs.python.org/issue6013

http://bugs.python.org/issue7451