Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的Javascript JSON格式等价物_Javascript_Python - Fatal编程技术网

Python中的Javascript JSON格式等价物

Python中的Javascript JSON格式等价物,javascript,python,Javascript,Python,我需要以这种JSON格式格式化某些内容: JSON.stringify(data,null,'\t'); 在python中如何执行此操作?对于python 3: import json json.dumps(data, indent='\t') 如果您正在使用Python 2或需要支持这两个版本,请使用simplejson模块: import simplejson as json Python2中的内置json模块仅使用空格缩进。“TypeError:不能将序列乘以'str'类型的非in

我需要以这种JSON格式格式化某些内容:

JSON.stringify(data,null,'\t');
在python中如何执行此操作?

对于python 3:

import json

json.dumps(data, indent='\t')
如果您正在使用Python 2或需要支持这两个版本,请使用
simplejson
模块:

import simplejson as json

Python2中的内置json模块仅使用空格缩进。

“TypeError:不能将序列乘以'str'类型的非int”@GabiPurcaru:您正在使用Python2<代码>将simplejson导入为json。您仍然可以缩进,只是不能使用
\t
选项卡<代码>缩进=4将使用4个空格而不是制表符。