您的位置:首页 > 编程语言 > Python开发

每天一篇python: json对象操作

2016-04-05 22:36 567 查看

使用python操作json

#!/usr/local/bin/python2.7
# -*- coding:utf-8 -*-
'''
Created on 2016年4月5日
python 操作json数据
@author: damuou
'''

import json

#1: 定义json字符串
json_str={"name": "lilei","sex": 'man',"age": 18}
print json_str
#把一个Python对象编码转换成Json字符串
print  json.dumps(json_str)

#把Json格式字符串解码转换成Python对象
s = json.loads('{"name":"test", "type":{"name":"seq", "parameter":["1", "2"]}}')
print s
print s.keys()
print s["name"]
print s["type"]["name"]
print s["type"]["parameter"][1]


这几天没状态。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: