python 日期时间和Json解析

一、JSON解析

(一) JOSN处理

1. JSON概述

JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。
如果你还不了解 JSON,可以先阅读我们的 JSON 教程。
Python3 中可以使用 json 模块来对 JSON 数据进行编解码,它包含了两个函数:
    json.dumps(): 对数据进行编码。 字符串到Json对象
    json.loads(): 对数据进行解码。 Json对象到python对象

2. Python 编码为 JSON 类型转换对应表:

Python	                                JSON
dict	                                object
list, tuple	                            array
str	                                    string
int, float, int- & float-derived Enums	number
True	                                true
False	                                false
None	                                null

3. JSON 解码为 Python 类型转换对应表:

JSON	        Python
object	        dict
array	        list
string	        str
number (int)	int
number (real)	float
true	        True
false	        False
null	        None

(二) 代码概述

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# @Date : 2024/6/17 10:54
# @Author : water
# @Description : json  解析器


"""
JSON概述
    JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。
    如果你还不了解 JSON,可以先阅读我们的 JSON 教程。
    Python3 中可以使用 json 模块来对 JSON 数据进行编解码,它包含了两个函数:
        json.dumps(): 对数据进行编码。 字符串到Json对象
        json.loads(): 对数据进行解码。 Json对象到python对象

Python 编码为 JSON 类型转换对应表:
    Python	                                JSON
    dict	                                object
    list, tuple	                            array
    str	                                    string
    int, float, int- & float-derived Enums	number
    True	                                true
    False	                                false
    None	                                null

JSON 解码为 Python 类型转换对应表:
    JSON	        Python
    object	        dict
    array	        list
    string	        str
    number (int)	int
    number (real)	float
    true	        True
    false	        False
    null	        None
"""

# json.dumps 与 json.loads 实例
import json

# Python 字典类型转换为 JSON 对象
data = {
   
    'no': 1,
    'name': 'Runoob',
    'url': 'https://www.runoob.com'
}

json_str = json.dumps(data)
print<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值