本文介绍了从请求库解析JSON响应的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python requests模块发送RESTful GET到服务器,我得到了JSON响应. JSON响应基本上只是列表的列表.

I'm using the python requests module to send a RESTful GET to a server, for which I get a response in JSON. The JSON response is basically just a list of lists.

强制对本地Python对象的响应的最佳方法是什么,以便我可以使用pprint进行迭代或将其打印出来?

What's the best way to coerce the response to a native Python object so I can either iterate or print it out using pprint?

推荐答案

您可以使用 json.loads :

You can use json.loads:

import json
import requests

response = requests.get(...)
json_data = json.loads(response.text)

这会将给定的字符串转换成字典,使您可以在代码中轻松访问JSON数据.

This converts a given string into a dictionary which allows you to access your JSON data easily within your code.

这篇关于从请求库解析JSON响应的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 21:06
查看更多