Python 操作 Json 基础入门

来源:互联网 发布:c语言assert函数 编辑:程序博客网 时间:2024/05/24 02:29
# -*- coding:utf-8 -*-# this module is used to testing json 's Encoding & Decoding,have funimport json#1.json.dumps 用于将 Python 对象编码成 JSON 字符串。data = [ { 'wumi' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]json1 = json.dumps(data)print json1#format datajsonformat = json.dumps(data,sort_keys=True,indent=4,separators=(',', ': '))  # indent=4, is what ? 缩进print jsonformat#2.json.loads 用于解码 JSON 数据。该函数返回 Python 字段的数据类型。jsonData = '{"a":1,"b":2,"c":3,"Ethan":4,"wumi":5}'print json.loads(jsonData)   # load has some issue     #{u'a': 1, u'wumi': 5, u'c': 3, u'b': 2, u'd': 4}# more info please refer to official site : https://docs.python.org/2/library/json.html#  更多使用参考第三方库 Demjson ,need extra install

原创粉丝点击