先看代码实例
import
json
a = {
'a'
:
'abc'
,
'b'
:
"bcd"
}
print json.dumps(a)
#输出:
{
"a"
:
"abc"
,
"b"
:
"bcd"
}
print json.dump(a)
#输出:
TypeError:Traceback (most recent call last)
<ipython-input-4-68d925ef8846>
in
<module>()
1 print json.dump(a)
TypeError: dump() takes at least 2 arguments (1 given)
如:
d = {'first': 'One', 'second':2}
json.dump(d, open('/tmp/result.txt', 'w'))