итерация по файлу json в python3 - PullRequest
0 голосов
/ 27 сентября 2019

Я учусь разбирать различные файлы (xml, json, csv) и собирать определенные значения в Python.Тем не менее, я не знаю, как идти о написании кода, чтобы найти такие вещи, как, например, в каком резюме фильма больше всего символов или общее количество фильмов.Мне было интересно, может ли кто-нибудь указать мне правильное направление или есть видео, которое помогает получить информацию из файла json.

Вот файл json:

[
    {
        "title": "A History of Violence",
        "year": "2005",
        "genre": "Crime",
        "summary": "Tom Stall, a humble family man and owner of a popular neighborhood restaurant, lives a quiet but fulfilling existence in the Midwest. One night Tom foils a crime at his place of business and, to his chagrin, is plastered all over the news for his heroics. Following this, mysterious people follow the Stalls' every move, concerning Tom more than anyone else. As this situation is confronted, more lurks out over where all these occurrences have stemmed from compromising his marriage, family relationship and the main characters' former relations in the process.",
        "country": "USA",

        "director": {
            "last_name": "Cronenberg",
            "first_name": "David",
            "birth_date": "1943"
        },
        "actors": [
            {
                "first_name": "Ed",
                "last_name": "Harris",
                "birth_date": "1950",
                "role": "Carl Fogarty"
            },
            {
                "first_name": "Vigo",
                "last_name": "Mortensen",
                "birth_date": "1958",
                "role": "Tom Stall"
            },
            {
                "first_name": "Maria",
                "last_name": "Bello",
                "birth_date": "1967",
                "role": "Eddie Stall"
            },
            {
                "first_name": "William",
                "last_name": "Hurt",
                "birth_date": "1950",
                "role": "Richie Cusack"
            }
        ]
    },
    {
        "title": "Marie Antoinette",
        "year": "2006",
        "genre": "Drama",
        "summary": "Based on Antonia Fraser's book about the ill-fated Archduchess of Austria and later Queen of France, 'Marie Antoinette' tells the story of the most misunderstood and abused woman in history, from her birth in Imperial Austria to her later life in France.",
        "country": "USA",

        "director": {
            "last_name": "Coppola",
            "first_name": "Sofia",
            "birth_date": "1971"
        },
        "actors": [
            {
                "first_name": "Kirsten",
                "last_name": "Dunst",
                "birth_date": "1982",
                "role": "Marie Antoinette"
            },
            {
                "first_name": "Jason",
                "last_name": "Schwartzman",
                "birth_date": "1980",
                "role": "Louis XVI"
            }
        ]
    },
    {
        "title": "Spider-Man",
        "year": "2002",
        "genre": "Action",
        "summary": "On a school field trip, Peter Parker (Maguire) is bitten by a genetically modified spider. He wakes up the next morning with incredible powers. After witnessing the death of his uncle (Robertson), Parkers decides to put his new skills to use in order to rid the city of evil, but someone else has other plans. The Green Goblin (Dafoe) sees Spider-Man as a threat and must dispose of him.",
        "country": "USA",

        "director": {
            "last_name": "Raimi",
            "first_name": "Sam",
            "birth_date": "1959"
        },
        "actors": [
            {
                "first_name": "Tobey",
                "last_name": "Maguire",
                "birth_date": "1975",
                "role": "Peter Parker"
            },
            {
                "first_name": "Tobey",
                "last_name": "Maguire",
                "birth_date": "1975",
                "role": "Spider-Man"
            },
            {
                "first_name": "Kirsten",
                "last_name": "Dunst",
                "birth_date": "1982",
                "role": "Mary Jane Watson"
            },
            {
                "first_name": "Willem",
                "last_name": "Dafoe",
                "birth_date": "1955",
                "role": "Green Goblin"
            },
            {
                "first_name": "Willem",
                "last_name": "Dafoe",
                "birth_date": "1955",
                "role": "Norman Osborn"
            }
        ]
    },
    {
        "title": "The Social network",
        "year": "2010",
        "genre": "Drama",
        "summary": "On a fall night in 2003, Harvard undergrad and computer programming genius Mark Zuckerberg sits down at his computer and heatedly begins working on a new idea. In a fury of blogging and programming, what begins in his dorm room soon becomes a global social network and a revolution in communication. A mere six years and 500 million friends later, Mark Zuckerberg is the youngest billionaire in history... but for this entrepreneur, success leads to both personal and legal complications.",
        "country": "USA",
        "director": {
            "last_name": "Fincher",
            "first_name": "David",
            "birth_date": "1962"
        },
        "actors": [
            {
                "first_name": "Jesse",
                "last_name": "Eisenberg",
                "birth_date": "1983",
                "role": "Mark Zuckerberg"
            },
            {
                "first_name": "Rooney",
                "last_name": "Mara",
                "birth_date": "1985",
                "role": "Erica Albright"
            },
            {
                "first_name": "Andrew",
                "last_name": "Garfield",
                "birth_date": "1983",
                "role": "Eduardo Saverin"
            },
            {
                "first_name": "Justin",
                "last_name": "Timberlake",
                "birth_date": "1981",
                "role": "Sean Parker"
            }
        ]
    },
    {
        "title": "Unforgiven",
        "year": "1992",
        "genre": "Western",
        "summary": "The town of Big Whisky is full of normal people trying to lead quiet lives. Cowboys try to make a living. Sheriff 'Little Bill' tries to build a house and keep a heavy-handed order. The town whores just try to get by.Then a couple of cowboys cut up a whore. Unsatisfied with Bill's justice, the prostitutes put a bounty on the cowboys. The bounty attracts a young gun billing himself as 'The Schofield Kid', and aging killer William Munny. Munny reformed for his young wife, and has been raising crops and two children in peace. But his wife is gone. Farm life is hard. And Munny is no good at it. So he calls his old partner Ned, saddles his ornery nag, and rides off to kill one more time, blurring the lines between heroism and villainy, man and myth.",
        "country": "USA",

        "director": {
            "last_name": "Eastwood",
            "first_name": "Clint",
            "birth_date": "1930"
        },
        "actors": [
            {
                "first_name": "Clint",
                "last_name": "Eastwood",
                "birth_date": "1930",
                "role": "William Munny"
            },
            {
                "first_name": "Gene",
                "last_name": "Hackman",
                "birth_date": "1930",
                "role": "Little Bill Dagget"
            },
            {
                "first_name": "Morgan",
                "last_name": "Freeman",
                "birth_date": "1937",
                "role": "Ned Logan"
            }
        ]
    }
]

1 Ответ

3 голосов
/ 27 сентября 2019

Есть пакет под названием json.Вы можете использовать это.

Это хорошая статья о работе с данными json в python

...