JSON Introduction:
O the JSON refers JavaScript Object Notation ( JavaScript Object Notation )
O the JSON is a lightweight text data interchange format
O JSON language independent
O the JSON self-descriptive better understood
* JSON using JavaScript syntax to describe data objects, but JSON is still independent of language and platform. JSON parser and JSON library supports many different programming languages.
Sequence and deserialization:
J S in JSON an object can be serialized data ( JSON . The stringify () ) and deserialize ( JSON . The parse () ) process;
py in json module ( Import json ) data may be serialized ( json.dumps () ) and deserialize ( json.loads () ) process.
JSON serialization date and time data types:
1 import json 2 from datetime import datetime,date 3 t = {'timer':datetime.now()} 4 5 class JsonCustomEncoder(json.JSONEncoder): 6 def default(self, field): 7 if isinstance(field,datetime): 8 return field.strftime('%Y-%m-%d %H:%M:%S') 9 elif isinstance(field,date): 10 return field.strftime('%Y-%m-%d') 11 else: 12 return json.JSONEncoder.default(self,field) 13 14 t_json = json.dumps(t,cls=JsonCustomEncoder) 15 print(t_json)