打印语句不在python中的控制台上打印任何内容。
我正在打印密钥以密钥开头的JSON文件的值@id
found = False
for key, di in json.loads(json_data).iteritems():
for k, v in di.items():
if k.startswith('@id'):
found = True
print k, v
sys.stout.flush()
break
if found:
break
我认为犯了一个错误。任何帮助将不胜感激。
答案 0 :(得分:0)
鉴于您在评论部分提供的样本数据,您可以尝试:
import json
json_data = '{ "nvd": { "entry": [ { "@id": "CVE-2016-0001", "vuln:cve-id": "CVE-2016-0001", "vuln:published-datetime": "2017-05-11T10:29:55.767-04:00", "vuln:last-modified-datetime": "2017-05-11T10:29:55.767-04:00", "vuln:summary": "** REJECT ** DO NOT USE THIS CANDIDATE NUMBER. " }]}}'
wantedKey = "@id"
found = False
for key, di in json.loads(json_data).items():
if wantedKey in di['entry'][0]:
found = True
print(wantedKey + " : " + di['entry'][0][wantedKey])
break
输出:
@id : CVE-2016-0001