json是可以和别的语言交互,转换后别的语言可以使用,但仅限于字符串,列表和字典
而pickle是python独有的,可以保存当前状态,可以存档
import json
#loads #--> 内部必须是双引号s = '{"desc":"invilad-citykey", "status":1002}'
l = [11,22,33,44]
result = json.loads(s)
print(result,type(result))
result = json.dumps(l)
print(result,type(result))
结果:
{'status': 1002, 'desc': 'invilad-citykey'}
[11, 22, 33, 44]
s = {"desc":"invilad-citykey", "status":1002}
l = [11,22,33,44]
a = json.dump(s,open("db","w", encoding="utf-8"))
b = json.load(open("db","r", encoding="utf-8"))
print(b, type(b))