-1
私はPythonで開いた.jsonファイルを持っています。しかし、私は、すべてを印刷するのではなく、.jsonファイルからorderIdsを抽出するだけです。ここに私のコードは、これまでです:私はPythonで開くことができる.jsonファイルを持っていますが、どのようにしてそこから特定の情報を抽出できますか?
import json
from pprint import pprint
import
with open('data-3.json') as data_file:
data = json.load(data_file)
pprint(data)
、ここでは私の.jsonファイルです:
{'orders': [{'createdTime': '2016-02-29T23:26:32Z',
'currentStatus': {'additionalProperties': {},
'customInfo': None,
'stateActionDescription': None,
'stateCode': 'DESPATCH_END',
'stateDescription': 'Despatch completed',
'stateType': 'DISPATCH',
'timestamp': '2016-03-02T12:47:26Z',
'updateId': 378379,
'user': 'Dave Ffitch'},
データの注文['orders']:print( '[currentStatus'] [whatever]) '...! – deceze
トレース[最近の呼び出し最後]: ファイル "/ Users/Jess/Documents/First Attempt.py"、行5、 データ['orders']での注文:print(order ['currentStatus'] [ 'orderId']) KeyError: 'orderId' @deceze –
さて、ええと... **あなたのJSONデータに 'orderId'はありません** – deceze