如何从json对象访问元素

2024-03-29 10:34:07 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用beautifulsoup或regex从json对象访问每个元素?你知道吗

例如,调用timestamp并获取输出=1561238146781

{
  "timestamp" : 1561238146781,
  "context" : {
    "external_urls" : {
      "spotify" : "https://open.spotify.com/playlist/4rwZyPeww8O7ZPnQqHD2q"
    },
    "href" : "https://api.spotify.com/v1/playlists/4rwZyPqew8O7ZPnQqHD2q",
    "type" : "playlist",
    "uri" : 
"spotify:user:3sui5bqpr8a0i2t:playlist:4rwZyPqewO7ZPnQqHD2q"
  },
  "progress_ms" : 115728,
  "item" : {
    "album" : {
      "album_type" : "album",
      "artists" : [ {
        "external_urls" : {
          "spotify" : 
"https://open.spotify.com/artist/5eAWCfyUhZqwHtBdNk56l1"
        },
        "href" : 
"https://api.spotify.com/v1/artists/5eAWCfyeZtHHtBdNk56l1",
        "id" : "5eAWCfyUhZtHHtBdNk56l1",
        "name" : "System Of A Down",
        "type" : "artist",
        "uri" : "spotify:artist:5eAWewyUhZtHHtBdNk56l1"
      } ],
      "available_markets" : [ ],
      "external_urls" : {
        "spotify" : "https://open.spotify.com/album/4DR0Gds7w2GJyQnFVa4jAB"
      },
      "href" : "https://api.spotify.com/v1/albums/4DR0ewwsdJyQnFVa4jAB",
      "id" : "4DR0GWo7w2ewyQnFVa4jAB",
      "images" : [ {
        "height" : 640,
        "url" : 
"https://i.scdn.co/image/932e185b217ew6caasd837dbe30d54028de9cfc",
        "width" : 615
      }, {
        "height" : 300,
        "url" : 
"https://i.scdn.co/image/30de1d4e1ew38sd89573893d8494fd6a66",
        "width" : 288
      }, {
        "height" : 64,
        "url" : 
"https://i.scdn.co/image/1682cd0e8ew8bf87sdc4cd1e01ce24cd165b",
        "width" : 62
      } ],
      "name" : "Toxicity",
      "release_date" : "2001-01-01",
      "release_date_precision" : "day",
      "total_tracks" : 14,
      "type" : "album",
      "uri" : "spotify:album:4DR0GewdGJyQnFVa4jAB"
    },
    "artists" : [ {
      "external_urls" : {
        "spotify" : "https://open.spotify.com/artist/5eAWCsdUweHtBdNk56l1"
      },
      "href" : "https://api.spotify.com/v1/artists/5eAWCfewhdsHtBdNk56l1",
      "id" : "5eAWCfyUhZtHHtBewk56l1",
      "name" : "System Of A Down",
      "type" : "artist",
      "uri" : "spotify:artist:5eAWCfyUsdtHHtBdNk56l1"
    } ],
    "available_markets" : [ ],
    "disc_number" : 1,
    "duration_ms" : 235599,
    "explicit" : false,
    "external_ids" : {
      "isrc" : "USSM10107264"
    },
    "external_urls" : {
      "spotify" : "https://open.spotify.com/track/1twBtsdaZiy7HWPG025QGuP"
    },
    "href" : "https://api.spotify.com/v1/tracks/1twBt7aZiy7HWPG025QGuP",
    "id" : "1twBt7aZiy7HWweG025QGuP",
    "is_local" : false,
    "name" : "Aerials",
    "popularity" : 9,
    "preview_url" : null,
    "track_number" : 14,
    "type" : "track",
    "uri" : "spotify:track:1twBt7aZieWPG025QGuP"
  },
  "currently_playing_type" : "track",
  "actions" : {
    "disallows" : {
      "resuming" : true
    }
  },
  "is_playing" : true
}

打电话“正在玩”并实现

我试着把孔数组做成一个列表(每个元素),并试图从列表中获取元素,但我意识到这几乎没有用。你知道吗


Tags: httpscomapialbumartisttypetrackuri