diff --git a/serializing.html b/serializing.html index 2f6ec3a..0ffbb7a 100644 --- a/serializing.html +++ b/serializing.html @@ -569,12 +569,13 @@ NameError: name 'entry' is not defined
json.load() doesn’t know anything about any conversion function you may have passed to json.dump(). What you need is the opposite of the to_json() function — a function that will take a custom-converted JSON object and convert it back to the original Python datatype.
-def from_json(json_object): ①
- if '__class__' in json_object: ②
+# add this to customserializer.py
+def from_json(json_object): ①
+ if '__class__' in json_object: ②
if json_object['__class__'] == 'time.asctime':
- return time.strptime(json_object['__value__']) ③
+ return time.strptime(json_object['__value__']) ③
if json_object['__class__'] == 'bytes':
- return bytes(json_object['__value__']) ④
+ return bytes(json_object['__value__']) ④
return json_object