直接看代码吧
# encoding:utf-8 from urllib.parse import quote import urllib.request import string import json url = quote('http://test.com:8080/api/v1/grafana/metrics/find?query=office-test-003#cpu#idle', safe=string.printable); #falcon的grafana接口 result = urllib.request.urlopen(url).read() #url请求 json_result = json.loads(result.decode()) #转换成list print (json.dumps(json_result,indent=2)) #json格式输出 |
--------------------结果输出------------------------
[
{
"expandable": false,
"text": "steal"
},
{
"expandable": false,
"text": "idle"
},
]