赞
踩
取出文件中的内容
- import json
-
- def python_to_json():
- d={
- 'name':'python数据'
- }
- rest=json.dumps(d)
- print(rest)
-
-
- if __name__ == '__main__':
- python_to_json()
- import json
-
- def python_to_json():
- d={
- 'name':'python数据'
- }
- #python对象转json
- rest=json.dumps(d)
- print(rest)
-
- def json_to_python():
- data= '''{
- "key1":12,
- "key2":"abc",
- "key5":{
- "key5_1":551,
- "key5_2":"key5_2_value"
- },
- "key6":[
- {"key6_1-1":6611,
- "key6_1——2":"key_1_2_value"
- },
- {"key6_2-1":6622,
- "key6_2——2":"key_2_2_value"
- }
- ]
- }'''
- #json转python对象
- rest=json.loads(data)
- print(rest)
-
- if __name__ == '__main__':
- # python_to_json()
- json_to_python()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。