English 中文(简体)
在json.loads上跳板给我的数据不同于json.dumps(json.loads)的数据。
原标题:Iterating on a json.loads give me different data than the one in the json.dumps(json.loads)
  • 时间:2024-03-10 02:39:05
  •  标签:
  • python
  • json

I m iterating on a json.loads object that have all the info i need (original_title) When i iterate on it i got incomplete result. Where is my mistake ? How can i improve this code to have complete result?

我的法典:

TMDB_TOKEN = "PUT YOURS HERE IF YOU WANNA TEST"
headers = {
    "accept": "application/json",
    "Authorization":  TMDB_TOKEN
    }
id = 17520
url = "https://api.themoviedb.org/3/person/{person_id}/movie_credits".format(person_id=id)
response = requests.get(url, headers=headers,)
parsed = json.loads(response.text)
print(json.dumps(parsed, indent=1))
all_filmo = { "doc":[] ,  cinema : [] , "tv" : [] }
for i in parsed[ cast ]:
    print(i[ original_title ])

你们可以看到存在失踪的LOT。

<代码>json.dumps。 i 仅保留原始标题

   "original_title": "Cinu00e9ma par... Cu00e9dric Klapisch",
   "original_title": "Quand Jean devint Renoir",
   "original_title": "Toujours pas ... A bout de souffle",
   "original_title": "Babyphone",
   "original_title": "Un air de famille",
   "original_title": "In Transit",
   "original_title": "Belmondo l influenceur",
   "original_title": "Les Poupu00e9es russes",
   "original_title": "Peut-u00eatre",
   "original_title": "Casse-Tu00eate Chinois",
   "original_title": "Ballerina",
   "original_title": "Belmondo, il u00e9tait une fois le beau monde",
   "original_title": "L Auberge espagnole",
   "original_title": "Ce qui nous lie",
   "original_title": "Le Pu00e9ril jeune",
   "original_title": "Le ramoneur des lilas",
   "original_title": "Babysitter",
   "original_title": "L Auberge espagnole",
   "original_title": "Les Poupu00e9es russes",
   "original_title": "Paris",
   "original_title": "Peut-u00eatre",
   "original_title": "Ni pour, ni contre (bien au contraire)",
   "original_title": "Chacun cherche son chat",
   "original_title": "Le Pu00e9ril jeune",
   "original_title": "Un air de famille",
   "original_title": "Lumiu00e8re et Compagnie",
   "original_title": "Riens du tout",
   "original_title": "Ma part du gu00e2teau",
   "original_title": "Casse-Tu00eate Chinois",
   "original_title": "Ce qui me meut",
   "original_title": "In Transit",
   "original_title": "Ce qui nous lie",
   "original_title": "Le ramoneur des lilas",
   "original_title": "Deux moi",
   "original_title": "Auru00e9lie Dupont, l espace d un instant",
   "original_title": "En corps",
   "original_title": "Le Poisson rouge",
   "original_title": "La Fu00eate du Cinu00e9ma",
   "original_title": "La Venue de lu2019Avenir",
   "original_title": "Casse-Tu00eate Chinois",
   "original_title": "Paris",
   "original_title": "Ce qui nous lie",
   "original_title": "Les Confins du monde",
   "original_title": "Princesses",
   "original_title": "Deux moi",
   "original_title": "L Auberge espagnole",
   "original_title": "Les Poupu00e9es russes",
   "original_title": "Paris",
   "original_title": "Chacun cherche son chat",
   "original_title": "Peut-u00eatre",
   "original_title": "Le Pu00e9ril jeune",
   "original_title": "Casse-Tu00eate Chinois",
   "original_title": "Ce qui me meut",
   "original_title": "Ni pour, ni contre (bien au contraire)",
   "original_title": "Ma part du gu00e2teau",
   "original_title": "Un air de famille",

我的热情结果:

Cinéma par... Cédric Klapisch
Quand Jean devint Renoir
Toujours pas ... A bout de souffle
Babyphone
Un air de famille
In Transit
Belmondo l influenceur
Les Poupées russes
Peut-être
Casse-Tête Chinois
Ballerina
Belmondo, il était une fois le beau monde
L Auberge espagnole
Ce qui nous lie
Le Péril jeune
Le ramoneur des lilas
问题回答

因为response 形式:

{
  cast: [{...original title}],
  crew: [{...original title}]
}

但是,该书仅以<代码>cast钥匙为准。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签