2014-01-11 32 views

回答

1

對於Python 3:只有2個縮進

import simplejson as json 

的內置json模塊在Python:

import json 

json.dumps(data, indent='\t') 

如果你正在使用Python 2或需要支持兩個版本,使用simplejson模塊與空間。 「

+0

」TypeError:不能通過類型爲'str'的非整型序列「 –

+0

@GabiPurcaru:您正在使用Python 2.」import simplejson as json' instead。 – Blender

+2

您仍然可以縮進,而不是使用'\ t'選項卡。 'indent = 4'將使用4個空格而不是製表符。 –