【问题标题】:How to parse json from wp-scan? [duplicate]如何从 wp-scan 解析 json? [复制]
【发布时间】:2016-07-28 06:23:18
【问题描述】:
{
"crius":{
"latest_version":null,"last_updated":null,"popular":false,"vulnerabilities":
    [{
    "id":7306,
    "title":"Crius - VideoJS Cross-Site Scripting Vulnerability",
    "created_at":"2014-08-01T10:59:16.000Z",
    "updated_at":"2015-05-15T13:48:44.000Z",
    "published_date":null,
    "references":{"url":["http://seclists.org/fulldisclosure/2013/May/77"],"secunia":["53427"]},"vuln_type":"XSS","fixed_in":null}]}
}

如何用 python 2.7 解析它们?谢谢。

【问题讨论】:

标签: python python-2.7


【解决方案1】:

使用json.loads():

import json

s = '''{
"crius":{
"latest_version":null,"last_updated":null,"popular":false,"vulnerabilities":
    [{
    "id":7306,
    "title":"Crius - VideoJS Cross-Site Scripting Vulnerability",
    "created_at":"2014-08-01T10:59:16.000Z",
    "updated_at":"2015-05-15T13:48:44.000Z",
    "published_date":null,
    "references":{"url":["http://seclists.org/fulldisclosure/2013/May/77"],"secunia":["53427"]},"vuln_type":"XSS","fixed_in":null}]}
}'''

data = json.loads(s)

>>> data
{u'crius': {u'popular': False, u'vulnerabilities': [{u'title': u'Crius - VideoJS Cross-Site Scripting Vulnerability', u'created_at': u'2014-08-01T10:59:16.000Z', u'updated_at': u'2015-05-15T13:48:44.000Z', u'vuln_type': u'XSS', u'references': {u'url': [u'http://seclists.org/fulldisclosure/2013/May/77'], u'secunia': [u'53427']}, u'published_date': None, u'fixed_in': None, u'id': 7306}], u'last_updated': None, u'latest_version': None}}

【讨论】:

  • 打印数据["latest_version"] KeyError: 'latest_version' ???
  • @LyĐào .. 你以为简单的data["latest_version"] 会简单地给你相应的值吗???..com'n...这是一个嵌套字典!!!
  • 看你的数据结构:要访问“latest_version”,你需要使用data["crius"]["latest_version"]
猜你喜欢
  • 1970-01-01
  • 2014-03-20
  • 2013-05-19
  • 2016-10-22
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 2017-04-08
相关资源
最近更新 更多