python module json
import
json
x
=
"[null,true,false,1]"
print
(json.loads(x))
#----------------------------Serialization import json dic={'name':'alvin','age':23,'sex':'male'} print(type(dic))#<class 'dict'> j=json.dumps(dic) print(type(j))#<class 'str'> f=open('Serialized object','w') f.write(j) #-------------------equivalent to json.dump(dic,f) f.close() #-----------------------------Deserialization<br> import json f=open('serialize object') data=json.loads(f.read())# is equivalent to data=json.load(f)
import json #dct="{'1':111}"#json does not recognize single quotes #dct=str({"1":111})#Error, because the generated data is still single quotes: {'one': 1} dct='{"1":"111"}' print(json.loads(dct)) #conclusion: # No matter how the data is created, as long as it meets the json format, it can be json.loads out, not necessarily the data of dumps to load