python 对json返回值进行序列化

# -*- ecoding: utf-8 -*-
# @ModuleName: test004
# @Function: 
# @Author: darling
# @Time: 2022-04-15 17:46

import requests


# linux执行登陆请调用下面的这句
def get_news():
    """获取金山词霸每日一句,英文和翻译"""
    url = "http://open.iciba.com/dsapi/"
    r = requests.get(url)
    content = r.json()['content']
    note = r.json()['note']
    return content, note


if __name__ == "__main__":
    res = get_news()
    print(res)

直接访问 接口地址,得到的是json 字符串,这里将字符串进行转json并取到其中的元素

posted @ 2022-04-18 19:34  darling331  阅读(49)  评论(0编辑  收藏  举报