Tools, FAQ, Tutorials:
What Is json.JSONEncoder Class
What Is json.JSONEncoder Class?
✍: FYIcenter.com
json.JSONEncoder class is the underlying class that supports json.dumps() functions.
The following Python example shows you how to use json.JSONEncoder class to perform the same JSON encoding job as json.dumps function:
>>> import json >>> l = ['foo', {'bar': ('baz', None, 1.0, {"c": 0, "b": 0, "a": 0})}] >>> # Encoding with json.dumps() function >>> j = json.dumps(l, indent=None, separators=(',', ':'), sort_keys=True) >>> print(j) ["foo",{"bar":["baz",null,1.0,{"a":0,"b":0,"c":0}]}] >>> # Encoding with json.JSONEncoder class >>> encoder = json.JSONEncoder(indent=None, separators=(',', ':'), sort_keys=True) >>> j = encoder.encode(l) >>> print(j) ["foo",{"bar":["baz",null,1.0,{"a":0,"b":0,"c":0}]}]
⇒ Extending json.JSONEncoder Class
2018-10-08, 2232🔥, 0💬
Popular Posts:
How To Set session.gc_divisor Properly in PHP? As you know that session.gc_divisor is the frequency ...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...
How To Use an Array as a Queue in PHP? A queue is a simple data structure that manages data elements...
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
How to detect errors occurred in the json_decode() call? You can use the following two functions to ...