赞
踩
""" JOSN数据和python字典的相互转换 """ import json #准备列表,表内每一个元素都是字典,将其转换为josn data=[{"name":"张三","age":11},{"name":"李四","age":15},{"name":"王五","age":13}] josn_str=json.dumps(data,ensure_ascii=False) print(josn_str) #准备字典,将字典转换为josn d={"name":"小二","age":11} josn_str=json.dumps(d,ensure_ascii=False) print(josn_str) #将josn字符串转换为python数据类型[{k:c,k:v},{k:v,k:v}] data='[{"name":"张三","age":11},{"name":"李四","age":15},{"name":"王五","age":13}]' l=json.loads(data) print(l) #将josn字符串转换为python数据类型{k:v,k:v} s='{"name":"小二","age":11}' d=json.loads(s) print(s)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。