import json
json_encode = json.dumps
json_decode = json.loads
a = '{"a":123}'
b = json_decode(a)
c = json_encode(b)
print 'original:'+a+'\n'
print 'decoded:' + str(b) + '\n'
print 'encoded' + c + '\n'
for python >= 2.6
implode and explode
实现explode
>>> str = 'a|b|c|d|e'
>>> str.split("|")
['a', 'b', 'c', 'd', 'e']
实现implode
>>> list = ['a', 'b', 'c', 'd', 'e']
>>> "|".join(list)
'a|b|c|d|e'
JSON编码与解码及字符串操作详解
本文详细介绍了Python中使用importjson模块进行JSON编码与解码的基本操作,并通过实例展示了如何使用json.dumps()与json.loads()函数进行转换。同时,文章还介绍了字符串分解与合并的方法,包括使用split()和join()函数处理字符串。
988

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



