See the code example first
In [1]: a = {' A ': ' abc ', ' B ': ' BCD '}in [2]: in [2]: Import Jsonin [3]: Print Json.dumps (a) {"A": "abc", "B": "BCD"}in [4]: Print Json.dump (a)---------------------------------------------------------------------------TypeError Traceback (most recent) <ipython-input-4-68d925ef8846> in <module> ()----> 1 print json.dump (a) Typeerror:dump () takes at least 2 arguments (1 given)
Dumps (obj, Skipkeys=false, Ensure_ascii=true, Check_circular=true, Allow_nan=true, Cls=none, Indent=None, separators= None, encoding= ' Utf-8 ', Default=none, Sort_keys=false, **kw)
Serialize ' obj ' to a JSON formatted ' str '.
Dump (obj, FP, Skipkeys=false, Ensure_ascii=true, Check_circular=true, Allow_nan=true, Cls=none, Indent=none, Separators=none, encoding= ' Utf-8 ', Default=none, Sort_keys=false, **kw)
Serialize ' obj ' as a JSON formatted stream to ' FP ' (a
". Write ()"-supporting File-like object).
Simply put, dump gives you something that is similar to a file pointer (not a real pointer), which can be combined with a file operation, and dumps directly to Str.
In practice, dump is seldom used.
The difference between Python json.dumps () json.dump ()