python:json,base 64の使用
750 ワード
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)