Python Can';t格式化JSON数据

Python Can';t格式化JSON数据,python,json,python-requests,Python,Json,Python Requests,下面是我从API调用中获得的示例JSON数据。但是当我试图格式化JSON数据时,我无法做到这一点 { “jsonrpc”:“2.0”, “结果”:[ { “状态”:“3”, “名称”:“Windows”, “触发器”:[ {“triggerid”:“11234”}, {“triggerid”:“5465”}, {“triggerid”:“56465”}, {“triggerid”:“56465”}, {“triggerid”:“54364”}, {“triggerid”:“564654”}, {

下面是我从API调用中获得的示例JSON数据。但是当我试图格式化JSON数据时,我无法做到这一点

{
“jsonrpc”:“2.0”,
“结果”:[
{
“状态”:“3”,
“名称”:“Windows”,
“触发器”:[
{“triggerid”:“11234”},
{“triggerid”:“5465”},
{“triggerid”:“56465”},
{“triggerid”:“56465”},
{“triggerid”:“54364”},
{“triggerid”:“564654”},
{“triggerid”:“564365”},
{“triggerid”:“5434”},
{“triggerid”:“54354”},
{“triggerid”:“5454”},
{“triggerid”:“5645”},
{“triggerid”:“543654”},
{“triggerid”:“546543”}
],
“项目”:[
{“名称”:“连接检查”},
{“name”:“正在运行的apache版本”},
{“名称”:“平均IOPS”},
{“名称”:“平均行驶速度”},
{“名称”:“文件速度”}
],
“templateid”:“456434”,
“发现”:[]
},
{
“状态”:“3”,
“名称”:“linux_服务器”,
“触发器”:[
{“triggerid”:“11234”},
{“triggerid”:“5465”},
{“triggerid”:“56465”},
{“triggerid”:“56465”},
{“triggerid”:“54364”},
{“triggerid”:“564654”},
{“triggerid”:“564365”},
{“triggerid”:“5434”},
{“triggerid”:“54354”},
{“triggerid”:“5454”},
{“triggerid”:“5645”},
{“triggerid”:“543654”},
{“triggerid”:“123543”}
],
“项目”:[
{“名称”:“连接检查”},
{“名称”:“docker运行版本”},
{“名称”:“平均IOPS”},
{“名称”:“平均行驶速度”},
{“名称”:“文件速度”}
],
“templateid”:“456434”,
“发现”:[]
}
]
}
我的代码:

output = requests.post(url, data=apache_data, headers=headers)
content_out = json.loads(output.content)
content_out = json.dumps(content_out)

for key in content_out .items():
  print(key)
错误:
AttributeError:“str”对象没有属性“items”

我想要“
名称”:“windows”
。。。。。。。。。。。。直到
“发现”:[]}
作为一本词典。类似于
“name”:“linux\u服务器”
。。。。。。。。直到
“发现”:[]}
作为另一本词典。。任何帮助都将不胜感激

你在用什么?通过调用
output.JSON()

因此,我认为使用您的代码,它看起来会像这样:

output=requests.post(url,data=apache_data,headers=headers)
对于output.json()['result']中的结果:
打印(结果['name']、结果['status']、结果['templateid'])
以下是输出:

Windows 3 456434
linux_server 3 456434

在您的示例中,
Windows
linux\u server
result
列表中的两个字典。

您留下了一行调试/实验代码,用于将解析后的JSON转换回字符串。尝试删除以下内容:

output = requests.post(url, data=apache_data, headers=headers )
# This parses your JSON correctly.
content_out = json.loads(ouput.content)
# This line turns your parsed JSON back into a string. You don't need this.
# content_out = json.dumps(content_out)

for key in content_out.items():
    print (key)

请格式化您的代码并定义
template\u out
变量。您粘贴的JSON示例至少缺少一个尾随
]}