import json
d={"name":"xxxx","age":21}
json_data=json.dumps(d)
print(json_data)
print(json.loads(json_data))
with open("seralize_data.txt",'wb') as f:
json.dump(d,f)
with open("seralize_data.txt",'rb') as f:
print(json.load(f))
Result:
{"age": 21, "name": "xxxx"}
{'age': 21, 'name': 'xxxx'}
Traceback (most recent call last):
File "./seralization.py", line 35, in <module>
json.dump(d,f)
File "/opt/python3.5/lib/python3.5/json/__init__.py", line 179, in dump
fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'
端庄的好喔
Result:
any one can tell me why?