JSON数据处理全解析
1. JSON概述
JSON(JavaScript Object Notation)常用于计算机系统间的交互式消息通信。在本地机器上运行的小型演示Web服务,虽用JavaScript/Node编写,但也可用其他编程语言实现。它提供RESTful接口,客户端可发送和接收JSON消息。
以下是一个HTTP请求响应的示例:
# A response to an HTTP request
response = requests.get('http://localhost:3001/users')
# Show status code, content-type, and JSON body
print(response.status_code, response.headers['Content-Type'])
response.text
输出结果可能为:
200 application/json; charset=utf-8
JSON中的空格不影响其含义,但能提高可读性。例如,使用 pprint_json 函数可对JSON进行格式化输出:
pprint_json(response.text)
输出示例:
{
"1": {
"name": "Guido van Rossum",
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



