Json python解析多个键

Json python解析多个键,json,dictionary,parsing,Json,Dictionary,Parsing,我有一个API,它返回这样的响应 data = [ {'id': 'x27fujsjfsfjsjf', 'price': '89992', 'type': 'ONE'}, {'id': 'ujufajfjfwau', 'price': '7777', 'type': 'ONE'}, {'id': 'x27adarasda', 'price': '88882', 'type': 'TWO'} ] 我想成对地解析响应,例如id和price。我使用PythonWebSocket客户端实时

我有一个API,它返回这样的响应

data = [
  {'id': 'x27fujsjfsfjsjf', 'price': '89992',  'type': 'ONE'}, {'id': 'ujufajfjfwau', 'price': '7777',  'type': 'ONE'}, {'id': 'x27adarasda', 'price': '88882',  'type': 'TWO'}
] 
我想成对地解析响应,例如id和price。我使用PythonWebSocket客户端实时获取数据

现在我使用:

 for d in data: 
       print (d['id])
但是我找不到一个同时解析id、price和type的解决方案。因为我对特定ID的价格感兴趣。

您可以这样做

for d in data:
    print (d['id'], d['price'], d['type'])
如果您想在某个地方使用这些值,可以用相同的方式将这些值传递给另一个函数


在这个

中有更多信息,您只需从字典中“说出”您想要打印的内容:

data = [
        {'id': 'x27fujsjfsfjsjf', 'price': '89992', 'type': 'ONE'},
        {'id': 'ujufajfjfwau', 'price': '7777',  'type': 'ONE'},
        {'id': 'x27adarasda', 'price': '88882',  'type': 'TWO'}
]

for item in data:
    print(item['id']) # this prints out the value of the ID
    print(item['price']) # this prints out the value of the PRICE
    print(item['type']) # this prints out the value of the TYPE

你是否在每个对象中都漏掉了一个逗号,还是像那样?没有,现在已修复。谢谢,汉克斯,你只想把身份证、价格和类型一起打印吗?是的,没错。我不知道这对我来说怎么会这么难弄明白:(这似乎是一项容易的任务。