首页 > 解决方案 > 如何在纯 JS 中仅操作 JSON 对象的一部分?

问题描述

假设我有这个JSON 响应,我只想从AddedDate属性中检索日期(而不是时间)或以正确的方式显示BreachDate( dd -mm-yy)。我怎样才能在纯 JS 中做到这一点?

标签: javascriptjson

解决方案


var json=[
  {
    "Name": "BattlefieldHeroes",
    "Title": "Battlefield Heroes",
    "Domain": "battlefieldheroes.com",
    "BreachDate": "2011-06-26",
    "AddedDate": "2014-01-23T13:10:29Z",
    "ModifiedDate": "2014-01-23T13:10:29Z",
    "PwnCount": 530270,
    "Description": "In June 2011 as part of a final breached data dump, the hacker collective &quot;LulzSec&quot; <a href=\"http:\/\/www.rockpapershotgun.com\/2011\/06\/26\/lulzsec-over-release-battlefield-heroes-data\" target=\"_blank\" rel=\"noopener\">obtained and released over half a million usernames and passwords from the game Battlefield Heroes<\/a>. The passwords were stored as MD5 hashes with no salt and many were easily converted back to their plain text versions.",
    "LogoType": "svg",
    "DataClasses": [
      "Passwords",
      "Usernames"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "BusinessAcumen",
    "Title": "Business Acumen Magazine",
    "Domain": "businessacumen.biz",
    "BreachDate": "2014-04-25",
    "AddedDate": "2014-05-11T04:25:48Z",
    "ModifiedDate": "2014-05-11T04:25:48Z",
    "PwnCount": 26596,
    "Description": "In April 2014, the Australian \"Business Acumen Magazine\" website was <a href=\"http:\/\/1337mir.com\/cracked\/2014\/04\/businessacumen-biz-hacked-26000-user-password-leaked\/\" target=\"_blank\" rel=\"noopener\">hacked by an attacker known as 1337MiR<\/a>. The breach resulted in over 26,000 accounts being exposed including usernames, email addresses and password stored with a weak cryptographic hashing algorithm (MD5 with no salt).",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Names",
      "Passwords",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Forbes",
    "Title": "Forbes",
    "Domain": "forbes.com",
    "BreachDate": "2014-02-15",
    "AddedDate": "2014-02-15T11:24:42Z",
    "ModifiedDate": "2014-02-15T11:24:42Z",
    "PwnCount": 1057819,
    "Description": "In February 2014, the Forbes website <a href=\"http:\/\/news.cnet.com\/8301-1009_3-57618945-83\/syrian-electronic-army-hacks-forbes-steals-user-data\" target=\"_blank\" rel=\"noopener\">succumbed to an attack that leaked over 1 million user accounts<\/a>. The attack was attributed to the Syrian Electronic Army, allegedly as retribution for a perceived \"Hate of Syria\". The attack not only leaked user credentials, but also resulted in the posting of fake news stories to forbes.com.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Passwords",
      "User website URLs",
      "Usernames"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Gawker",
    "Title": "Gawker",
    "Domain": "gawker.com",
    "BreachDate": "2010-12-11",
    "AddedDate": "2013-12-04T00:00:00Z",
    "ModifiedDate": "2013-12-04T00:00:00Z",
    "PwnCount": 1247574,
    "Description": "In December 2010, Gawker was attacked by the hacker collective &quot;Gnosis&quot; in retaliation for what was reported to be a feud between Gawker and 4Chan. Information about Gawkers 1.3M users was published along with the data from Gawker's other web presences including Gizmodo and Lifehacker. Due to the prevalence of password reuse, many victims of the breach <a href=\"http:\/\/www.troyhunt.com\/2011\/01\/why-your-apps-security-design-could.html\" target=\"_blank\" rel=\"noopener\">then had their Twitter accounts compromised to send Acai berry spam<\/a>.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Passwords",
      "Usernames"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Hemmelig",
    "Title": "hemmelig.com",
    "Domain": "hemmelig.com",
    "BreachDate": "2011-12-21",
    "AddedDate": "2014-03-25T07:23:52Z",
    "ModifiedDate": "2014-03-25T07:23:52Z",
    "PwnCount": 28641,
    "Description": "In December 2011, Norway's largest online sex shop hemmelig.com was <a href=\"http:\/\/www.dazzlepod.com\/hemmelig\/?page=93\" target=\"_blank\" rel=\"noopener\">hacked by a collective calling themselves &quot;Team Appunity&quot;<\/a>. The attack exposed over 28,000 usernames and email addresses along with nicknames, gender, year of birth and unsalted MD5 password hashes.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Genders",
      "Nicknames",
      "Passwords",
      "Usernames",
      "Years of birth"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "LoungeBoard",
    "Title": "Lounge Board",
    "Domain": "loungeboard.net",
    "BreachDate": "2013-08-01",
    "AddedDate": "2014-07-06T10:22:01Z",
    "ModifiedDate": "2014-07-06T10:22:01Z",
    "PwnCount": 45018,
    "Description": "At some point in 2013, 45k accounts were <a href=\"http:\/\/leak.sx\/thread-186921\" target=\"_blank\" rel=\"noopener\">breached from the Lounge Board \"General Discussion Forum\" and then dumped publicly<\/a>. Lounge Board was a MyBB forum launched in 2012 and discontinued in mid 2013 (the last activity in the logs was from August 2013).",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "IP addresses",
      "Names",
      "Passwords",
      "Private messages",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "PokemonCreed",
    "Title": "Pok\u00e9mon Creed",
    "Domain": "pokemoncreed.net",
    "BreachDate": "2014-08-08",
    "AddedDate": "2014-08-10T00:03:59Z",
    "ModifiedDate": "2014-08-10T00:03:59Z",
    "PwnCount": 116465,
    "Description": "In August 2014, the Pok\u00e9mon RPG website <a href=\"http:\/\/pokemoncreed.net\" target=\"_blank\" rel=\"noopener\">Pok\u00e9mon Creed<\/a> was hacked after a dispute with rival site, <a href=\"http:\/\/pkmndusk.in\" target=\"_blank\" rel=\"noopener\">Pok\u00e9mon Dusk<\/a>. In a <a href=\"https:\/\/www.facebook.com\/ramandeep.s.dehal\/posts\/749666358442465\" target=\"_blank\" rel=\"noopener\">post on Facebook<\/a>, &quot;Cruz Dusk&quot; announced the hack then pasted the dumped MySQL database on <a href=\"http:\/\/pkmndusk.in\" target=\"_blank\" rel=\"noopener\">pkmndusk.in<\/a>. The breached data included over 116k usernames, email addresses and plain text passwords.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Genders",
      "IP addresses",
      "Passwords",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Verified",
    "Title": "Verified",
    "Domain": "verified.cm",
    "BreachDate": "2014-01-10",
    "AddedDate": "2014-07-06T04:16:37Z",
    "ModifiedDate": "2014-07-06T04:16:37Z",
    "PwnCount": 16919,
    "Description": "In January 2014, <a href=\"http:\/\/securityaffairs.co\/wordpress\/21120\/cyber-crime\/verified-communities-hacked.html\" target=\"_blank\" rel=\"noopener\">one of the largest communities of Eastern Europe cybercriminals known as \"Verified\" was hacked<\/a>. The breach exposed nearly 17k users of the vBulletin forum including their personal messages and other potentially personally identifiable information.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Historical passwords",
      "IP addresses",
      "Passwords",
      "Private messages",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Win7Vista",
    "Title": "Win7Vista Forum",
    "Domain": "win7vista.com",
    "BreachDate": "2013-09-03",
    "AddedDate": "2014-06-01T10:01:32Z",
    "ModifiedDate": "2014-06-01T10:01:32Z",
    "PwnCount": 202683,
    "Description": "In September 2013, the <a href=\"http:\/\/www.win7vista.com\" target=\"_blank\" rel=\"noopener\">Win7Vista<\/a> Windows forum (since renamed to the \"Beyond Windows 9\" forum) was hacked and later <a href=\"http:\/\/leak.sx\/thread-186933\" target=\"_blank\" rel=\"noopener\">had its internal database dumped<\/a>. The dump included over 200k members\u2019 personal information and other internal data extracted from the forum.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Instant messenger identities",
      "IP addresses",
      "Names",
      "Passwords",
      "Private messages",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  }
]


for(var i=0;i<json.length;i++){
  var strDate = json[i].AddedDate;

  console.log(strDate.substring(0, 10))
}

var json=[
  {
    "Name": "BattlefieldHeroes",
    "Title": "Battlefield Heroes",
    "Domain": "battlefieldheroes.com",
    "BreachDate": "2011-06-26",
    "AddedDate": "2014-01-23T13:10:29Z",
    "ModifiedDate": "2014-01-23T13:10:29Z",
    "PwnCount": 530270,
    "Description": "In June 2011 as part of a final breached data dump, the hacker collective &quot;LulzSec&quot; <a href=\"http:\/\/www.rockpapershotgun.com\/2011\/06\/26\/lulzsec-over-release-battlefield-heroes-data\" target=\"_blank\" rel=\"noopener\">obtained and released over half a million usernames and passwords from the game Battlefield Heroes<\/a>. The passwords were stored as MD5 hashes with no salt and many were easily converted back to their plain text versions.",
    "LogoType": "svg",
    "DataClasses": [
      "Passwords",
      "Usernames"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "BusinessAcumen",
    "Title": "Business Acumen Magazine",
    "Domain": "businessacumen.biz",
    "BreachDate": "2014-04-25",
    "AddedDate": "2014-05-11T04:25:48Z",
    "ModifiedDate": "2014-05-11T04:25:48Z",
    "PwnCount": 26596,
    "Description": "In April 2014, the Australian \"Business Acumen Magazine\" website was <a href=\"http:\/\/1337mir.com\/cracked\/2014\/04\/businessacumen-biz-hacked-26000-user-password-leaked\/\" target=\"_blank\" rel=\"noopener\">hacked by an attacker known as 1337MiR<\/a>. The breach resulted in over 26,000 accounts being exposed including usernames, email addresses and password stored with a weak cryptographic hashing algorithm (MD5 with no salt).",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Names",
      "Passwords",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Forbes",
    "Title": "Forbes",
    "Domain": "forbes.com",
    "BreachDate": "2014-02-15",
    "AddedDate": "2014-02-15T11:24:42Z",
    "ModifiedDate": "2014-02-15T11:24:42Z",
    "PwnCount": 1057819,
    "Description": "In February 2014, the Forbes website <a href=\"http:\/\/news.cnet.com\/8301-1009_3-57618945-83\/syrian-electronic-army-hacks-forbes-steals-user-data\" target=\"_blank\" rel=\"noopener\">succumbed to an attack that leaked over 1 million user accounts<\/a>. The attack was attributed to the Syrian Electronic Army, allegedly as retribution for a perceived \"Hate of Syria\". The attack not only leaked user credentials, but also resulted in the posting of fake news stories to forbes.com.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Passwords",
      "User website URLs",
      "Usernames"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Gawker",
    "Title": "Gawker",
    "Domain": "gawker.com",
    "BreachDate": "2010-12-11",
    "AddedDate": "2013-12-04T00:00:00Z",
    "ModifiedDate": "2013-12-04T00:00:00Z",
    "PwnCount": 1247574,
    "Description": "In December 2010, Gawker was attacked by the hacker collective &quot;Gnosis&quot; in retaliation for what was reported to be a feud between Gawker and 4Chan. Information about Gawkers 1.3M users was published along with the data from Gawker's other web presences including Gizmodo and Lifehacker. Due to the prevalence of password reuse, many victims of the breach <a href=\"http:\/\/www.troyhunt.com\/2011\/01\/why-your-apps-security-design-could.html\" target=\"_blank\" rel=\"noopener\">then had their Twitter accounts compromised to send Acai berry spam<\/a>.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Passwords",
      "Usernames"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Hemmelig",
    "Title": "hemmelig.com",
    "Domain": "hemmelig.com",
    "BreachDate": "2011-12-21",
    "AddedDate": "2014-03-25T07:23:52Z",
    "ModifiedDate": "2014-03-25T07:23:52Z",
    "PwnCount": 28641,
    "Description": "In December 2011, Norway's largest online sex shop hemmelig.com was <a href=\"http:\/\/www.dazzlepod.com\/hemmelig\/?page=93\" target=\"_blank\" rel=\"noopener\">hacked by a collective calling themselves &quot;Team Appunity&quot;<\/a>. The attack exposed over 28,000 usernames and email addresses along with nicknames, gender, year of birth and unsalted MD5 password hashes.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Genders",
      "Nicknames",
      "Passwords",
      "Usernames",
      "Years of birth"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "LoungeBoard",
    "Title": "Lounge Board",
    "Domain": "loungeboard.net",
    "BreachDate": "2013-08-01",
    "AddedDate": "2014-07-06T10:22:01Z",
    "ModifiedDate": "2014-07-06T10:22:01Z",
    "PwnCount": 45018,
    "Description": "At some point in 2013, 45k accounts were <a href=\"http:\/\/leak.sx\/thread-186921\" target=\"_blank\" rel=\"noopener\">breached from the Lounge Board \"General Discussion Forum\" and then dumped publicly<\/a>. Lounge Board was a MyBB forum launched in 2012 and discontinued in mid 2013 (the last activity in the logs was from August 2013).",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "IP addresses",
      "Names",
      "Passwords",
      "Private messages",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "PokemonCreed",
    "Title": "Pok\u00e9mon Creed",
    "Domain": "pokemoncreed.net",
    "BreachDate": "2014-08-08",
    "AddedDate": "2014-08-10T00:03:59Z",
    "ModifiedDate": "2014-08-10T00:03:59Z",
    "PwnCount": 116465,
    "Description": "In August 2014, the Pok\u00e9mon RPG website <a href=\"http:\/\/pokemoncreed.net\" target=\"_blank\" rel=\"noopener\">Pok\u00e9mon Creed<\/a> was hacked after a dispute with rival site, <a href=\"http:\/\/pkmndusk.in\" target=\"_blank\" rel=\"noopener\">Pok\u00e9mon Dusk<\/a>. In a <a href=\"https:\/\/www.facebook.com\/ramandeep.s.dehal\/posts\/749666358442465\" target=\"_blank\" rel=\"noopener\">post on Facebook<\/a>, &quot;Cruz Dusk&quot; announced the hack then pasted the dumped MySQL database on <a href=\"http:\/\/pkmndusk.in\" target=\"_blank\" rel=\"noopener\">pkmndusk.in<\/a>. The breached data included over 116k usernames, email addresses and plain text passwords.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Genders",
      "IP addresses",
      "Passwords",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Verified",
    "Title": "Verified",
    "Domain": "verified.cm",
    "BreachDate": "2014-01-10",
    "AddedDate": "2014-07-06T04:16:37Z",
    "ModifiedDate": "2014-07-06T04:16:37Z",
    "PwnCount": 16919,
    "Description": "In January 2014, <a href=\"http:\/\/securityaffairs.co\/wordpress\/21120\/cyber-crime\/verified-communities-hacked.html\" target=\"_blank\" rel=\"noopener\">one of the largest communities of Eastern Europe cybercriminals known as \"Verified\" was hacked<\/a>. The breach exposed nearly 17k users of the vBulletin forum including their personal messages and other potentially personally identifiable information.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Historical passwords",
      "IP addresses",
      "Passwords",
      "Private messages",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  },
  {
    "Name": "Win7Vista",
    "Title": "Win7Vista Forum",
    "Domain": "win7vista.com",
    "BreachDate": "2013-09-03",
    "AddedDate": "2014-06-01T10:01:32Z",
    "ModifiedDate": "2014-06-01T10:01:32Z",
    "PwnCount": 202683,
    "Description": "In September 2013, the <a href=\"http:\/\/www.win7vista.com\" target=\"_blank\" rel=\"noopener\">Win7Vista<\/a> Windows forum (since renamed to the \"Beyond Windows 9\" forum) was hacked and later <a href=\"http:\/\/leak.sx\/thread-186933\" target=\"_blank\" rel=\"noopener\">had its internal database dumped<\/a>. The dump included over 200k members\u2019 personal information and other internal data extracted from the forum.",
    "LogoType": "svg",
    "DataClasses": [
      "Email addresses",
      "Instant messenger identities",
      "IP addresses",
      "Names",
      "Passwords",
      "Private messages",
      "Usernames",
      "Website activity"
    ],
    "IsVerified": true,
    "IsFabricated": false,
    "IsSensitive": false,
    "IsRetired": false,
    "IsSpamList": false
  }
]

推荐阅读