安装:
pip install orjson
使用:
该库不提供用于读取/写入类文件对象的load()
或dump()
函数,只有dumps()跟loads().
import orjson
tmp = {} for i in range(1, 1000000): tmp[str(i+1)] = 1returns byte instead of stringjson_byte
res = orjson.dumps(data)
orjson.loads(res)
文件的读写:
您通常可以通过write()函数轻松地将字节内容保存到文件中。 以二进制的方式写入:
data = [xxx, xxx, ....]
with open("example.json", "wb") as f:
f.write(orjson.dumps(data))
with open("example.json", "rb") as f:
json_data = orjson.loads(f.read())