zoukankan      html  css  js  c++  java
  • Python之json文件

    {
        "people":[
            {
              "firstName": "Brett",
              "lastName":"McLaughlin"
            },
            {
              "firstName":"Jason",
              "lastName":"Hunter"
            }        
        ]
    }

    json简介

    • json是一种轻量级的数据交换格式
    • 完全独立于编程语言的文本格式来存储和表示数据
    • 简单和清晰的层次结构使得json成为理想的数据交换语言。易于阅读和编写,易于机器解析和生成,并有效地提升网络传输效率
    • json相比于xml来讲,数据体积小,传输速度快,格式都是压缩的
    • json格式语法上与创建JavaScript对象的代码相同,由于这种相似性,JavaScript程序可以轻松地将json数据转换为JaveScript对象

    json方法

    • load
    • loads:将已编码的 JSON 字符串解码为 Python 对象
    • dump
    • dumps:将 Python 对象编码成 JSON 字符串

    示例 

    #coding = utf-8
    
    import requests
    import json
    
    response = requests.get("http://httpbin.org/get")
    print(response.json())
    strtext = json.loads(response.text)
    print (type(strtext))
    
    for key,value in strtext.items():
        print (key,value)
        
    print (strtext["url"])
    {'args': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate
    onnection': 'close', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/
    4'}, 'origin': '111.175.40.89', 'url': 'http://httpbin.org/get'}
    <class 'dict'>
    args {}
    headers {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection':
    se', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}
    origin 111.175.40.89
    url http://httpbin.org/get
    http://httpbin.org/get
  • 相关阅读:
    ★★★
    ★★
    小狼程序员:工作遐想
    广联达BB了
    计算机网络简单理解
    做个合格的(优秀的)测试开发人员
    开发、测试、测试开发
    8.21
    C++ 选择题总结(回调函数 || 类方法(实例方法)|| )
    深拷贝实现笔记
  • 原文地址:https://www.cnblogs.com/xiaobingqianrui/p/8513724.html
Copyright © 2011-2022 走看看