如何打印接口的json
时间: 2024-05-01 09:21:33 浏览: 108
要打印接口的json,可以使用编程语言中的json库或者工具来格式化打印。以下是在Python中打印json的示例代码:
```python
import json
# 假设接口返回的json数据为response_json
response_json = {'name': 'John', 'age': 30, 'city': 'New York'}
# 使用json.dumps函数将json数据格式化为字符串,并指定缩进为4个空格
formatted_json = json.dumps(response_json, indent=4)
# 打印格式化后的json字符串
print(formatted_json)
```
输出结果如下:
```
{
"name": "John",
"age": 30,
"city": "New York"
}
```
其中,json.dumps函数可以将Python对象转换为json格式的字符串,并指定缩进的空格数。在本例中,我们将缩进设置为4个空格,使得输出的json字符串易于阅读。
阅读全文
相关推荐












