zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    ajax的基础知识
    前端必备的php的基础知识点
    关于事件的简单汇总
    Django rest-framework(目录)
    Django(目录)
    前端(目录)
    数据库知识(目录)
    数据库基础
    并发编程(目录)
    网络编程
  • 原文地址:https://www.cnblogs.com/TendToBigData/p/10501233.html
Copyright © 2011-2022 走看看