浏览 JSON 响应以捕获值
我试图在“标签”键下的“ process:ilapd”值中捕获“ ilapd”字符串,但尚未成功。我该如何抓住这个弦?
我试图用for循环的几个变量迭代数据,但要为类型整数遇到错误。
JSON数据下面:
data = {
"alertOwner":"team",
"assignGroup":"team",
"component":"lnx2",
"Tags":"application:unknown, appowner:secops, bgs:performance, businessgroup:top, drexercise:no, env:nonprod, facility:hq, host:lnx2, location:somewhere, manager:smith, monitor, monitoring24x7:yes, osowner:unix, process:ilapd",
"description":"Process ilapd is not running on lnx2, expected state is running,",
"Event Url":"https://app.datadoghq.com/monitors#67856691",
"logicalName":"lnx2",
"Metric Graph":"<img src=\"\" />",
"pageGroups":"team",
"priority":"4",
"Snapshot Link":"",
"type":"test"
}
I am trying to capture the "ilapd" string in the "process:ilapd" value under the "Tags" key but have not been successful. How do I go about grabbing this string?
I have tried to iterate through the data with several variables of a for loop but keep getting errors for type integers.
JSON data below:
data = {
"alertOwner":"team",
"assignGroup":"team",
"component":"lnx2",
"Tags":"application:unknown, appowner:secops, bgs:performance, businessgroup:top, drexercise:no, env:nonprod, facility:hq, host:lnx2, location:somewhere, manager:smith, monitor, monitoring24x7:yes, osowner:unix, process:ilapd",
"description":"Process ilapd is not running on lnx2, expected state is running,",
"Event Url":"https://app.datadoghq.com/monitors#67856691",
"logicalName":"lnx2",
"Metric Graph":"<img src=\"\" />",
"pageGroups":"team",
"priority":"4",
"Snapshot Link":"",
"type":"test"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
str.split
+str.startswith
:打印:
或使用
re
模块:You can use
str.split
+str.startswith
:Prints:
Or using
re
module: