python处理网络请求返回的json数据示例

import requests
import json
from pprint import pprint

# GET
url = "http://localhost:3000/api/category?pageNum=1&pageSize=20"
r = requests.get(url)
res = r.json()
data = res['data']
# pprint(data)
list = data['list']
# pprint(list)
for index in range(len(list)):
    item = list[index]
    bookList = item['bookList']
    categoryName = item['categoryName']
    type = item['type']
    # pprint(bookList)
    # pprint(categoryName)
    # pprint(type)
    for ii in range(len(bookList)):
        book = bookList[ii]
        # pprint(book)
        author = book['author']
        pprint(author)
    break



# POST
# payload = {'key1': 'value1', 'key2': 'value2'}
# r = requests.post("http://httpbin.org/post", data=payload)
# res = r.json()

你可能感兴趣的:(python处理网络请求返回的json数据示例)