Python 操作 Json 基础入门

# -*- coding:utf-8 -*-
# this module is used to testing json 's Encoding & Decoding,have fun
import json

#1.json.dumps 用于将 Python 对象编码成 JSON 字符串。

data = [ { 'wumi' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]
json1 = json.dumps(data)
print json1
#format data
jsonformat = 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

转载于:https://www.cnblogs.com/TendToBigData/p/10501233.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值