有没有一种简单的方法来估算json对象的大小?

编程入门 行业动态 更新时间:2024-10-25 03:22:36
本文介绍了有没有一种简单的方法来估算json对象的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个安全服务,该服务将返回权限列表,并且我正在尝试估计json响应对象的大小.这是一段示例数据:

I'm working on a security service that will return a list of permissions and I'm trying to estimate the size of the json response object. Here's a piece of sample data:

ID = 123 VariableName = CanAccessSomeContent

ID=123 VariableName=CanAccessSomeContent

我正在寻找一种简单的方法来估计1500行时json响应对象的大小.是否可以使用在线估算工具或其他一些技术轻松获得粗略的估算值?

I'm looking for an easy way to estimate what size of the json response object will be with 1500 rows. Is there an online estimation tool or some other technique I can use to easily get a rough size estimate?

推荐答案

使用Python,您可以通过创建字典来估计大小,也可以只制作一个...

Using Python you can estimate the size by creating the dictionary or just make one...

import json import os import sys dict = {} for a in range(0, 1500): dict[a] = {'VariableName': 'CanAccessSomeContent'} output = json.dumps(dict, indent = 4) print ("Estimated size: " + str(sys.getsizeof(output) / 1024) + "KB") with open( "test.json", 'wb') as outfile: outfile.write(output) print ("Actual size: " + str(os.path.getsize('test.json') / 1024) + "KB")

输出:

Estimated size: 100KB Actual size: 99KB

更多推荐

有没有一种简单的方法来估算json对象的大小?

本文发布于:2023-10-27 23:36:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534864.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法来   对象   大小   简单   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!