在Python中比较JSON文件中的键与列表中的值[已关闭]

zlhcx6iw  于 2023-08-08  发布在  Python
关注(0)|答案(1)|浏览(119)

已关闭。此问题需要details or clarity。它目前不接受回答。
**希望改进此问题?**通过editing this post添加详细信息并阐明问题。

10天前关门了。
Improve this question
我需要将这个JSON文件中的标题与列表中的标题进行比较。我的目标是检查哪些标题等于这个列表的值,然后打印有关该标题的信息。例如,如果其中一个标题是Bloons TD 6,我只想打印相应的描述和viewableDate。
以下是我目前掌握的情况

response = requests.get("https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=en-US&country=US&allowCountries=US")

freeGameData = json.loads(response.text)
freeNowList = Epic_Scraper()

#freeNowList returns ['Bloons TD 6', 'Loop Hero']
#freeGameData returns the json listed below

字符串
Json文件如下所示

{
    "data": {
        "Catalog": {
            "searchStore": {
                "elements": [
                    {
                        "title": "Loop Hero",
                        "id": "db122f42b41f4dec927e0f280cf653bd",
                        "namespace": "ff50f85ed609454e80ac46d9496da34d",
                        "description": "The Lich has thrown the world into a timeless loop and plunged its inhabitants into never ending chaos. Wield an expanding deck of mystical cards to place enemies, buildings, and terrain along each unique expedition loop for the brave hero.",
                        "effectiveDate": "2021-03-04T18:00:00.000Z",
                        "offerType": "BASE_GAME",
                        "expiryDate": null,
                        "viewableDate": "2021-03-04T18:00:00.000Z",
                        "status": "ACTIVE",
                        "isCodeRedemptionOnly": false,
                    },
                    {
                        "title": "Bloons TD 6",
                        "id": "b27e3b556f1048b9824c7196f32afceb",
                        "namespace": "6a8dfa6e441e4f2f9048a98776c6077d",
                        "description": "The Bloons are back and better than ever! Get ready for a massive 3D tower defense game designed to give you hours and hours of the best strategy gaming available.",
                        "effectiveDate": "2022-07-19T12:00:00.000Z",
                        "offerType": "BASE_GAME",
                        "expiryDate": null,
                        "viewableDate": "2022-04-30T00:00:00.000Z",
                        "status": "ACTIVE",
                        "isCodeRedemptionOnly": false,
                    },
                    {
                        "title": "Destiny 2: Bungie 30th Anniversary Pack",
                        "id": "e7b9e222c7274dd28714aba2e06d2a01",
                        "namespace": "428115def4ca4deea9d69c99c5a5a99e",
                        "description": "The 30th Anniversary Pack includes a new Dungeon, Gjallarhorn Exotic Rocket Launcher, new weapons, armor, and much more.                    ",
                        "effectiveDate": "2022-08-23T13:00:00.000Z",
                        "offerType": "DLC",
                        "expiryDate": null,
                        "viewableDate": "2022-08-08T15:00:00.000Z",
                        "status": "ACTIVE",
                        "isCodeRedemptionOnly": false,
                        },
                    },

}

8iwquhpp

8iwquhpp1#

循环遍历json最里面的列表,只有标题在列表中时才打印信息:

for e in freeGameData["data"]["Catalog"]["searchStore"]["elements"]:
    if e["title"] in freeNowList:
        print(e["description"])
        print(e["viewableDate"]+"\n")

字符串

相关问题