JSON
1. import json
2. json.dumps() json obj => string
3. json.load() string => json obj
Base64
1. import json
2. json.dumps() json obj => string
3. json.load() string => json obj
Base64
import base64
import StringIO
a = "this is a test"
b = base64.encodestring(a) # 对字符串编码
print b
print base64.decodestring(b) # 对字符串解码
c = StringIO.StringIO()
c.write(a)
d = StringIO.StringIO()
e = StringIO.StringIO()
c.seek(0)
base64.encode(c, d) # 对StringIO内的数据进行编码
print d.getvalue()
d.seek(0)
base64.decode(d, e) # 对StringIO内的数据进行解码
print e.getvalue()
a = "this is a +test"
b = base64.urlsafe_b64encode(a) # 进行url的字符串编码
print b
print base64.urlsafe_b64decode(b)
本文深入探讨了JSON数据格式与Base64编码之间的转换过程,包括使用Python库进行字符串到JSON对象和JSON对象到字符串的转换,以及Base64编码与解码的应用场景与实现方式。
1178

被折叠的 条评论
为什么被折叠?



