のは、それが直接JSONデータだ
(デバッグ部分をスキップ)[]
文字から始まる入力文字列を定義してみましょう:Pythonの辞書のリストにunserializes
import json
text='''[{"EffectiveTime":"01-Oct-2016 04:00:00","EurPrice":30.460,"GbpPrice":26.260,
"RunType":"EP2","SystemLoad":2702.651},{"EffectiveTime":"01-Oct-2016 04:30:00","EurPrice":30.460,"GbpPrice":26.260,"RunType":"EP2",
"SystemLoad":2694.620},{"EffectiveTime":"01-Oct-2016 05:00:00","EurPrice":30.510,"GbpPrice":26.300,"RunType":"EP2","SystemLoad":2718.430}]'''
dict_list = json.loads(text)
for d in dict_list:
print(d)
結果:
{u'GbpPrice': 26.26, u'EffectiveTime': u'01-Oct-2016 04:00:00', u'EurPrice': 30.46, u'SystemLoad': 2702.651, u'RunType': u'EP2'}
{u'GbpPrice': 26.26, u'EffectiveTime': u'01-Oct-2016 04:30:00', u'EurPrice': 30.46, u'SystemLoad': 2694.62, u'RunType': u'EP2'}
{u'GbpPrice': 26.3, u'EffectiveTime': u'01-Oct-2016 05:00:00', u'EurPrice': 30.51, u'SystemLoad': 2718.43, u'RunType': u'EP2'}
フル・ダンプでも同じ結果が得られますデバッグヘッダーを含む)は次のようになります。
import json
text='''{"Debug":"Key:01-Oct-2016 04:00:00_04-Dec-2016 23:45:00,Age:-1","ErrorMessage":null,"LastUpdated":"06-Dec-2016 15:14:14","Rows":
[{"EffectiveTime":"01-Oct-2016 04:00:00","EurPrice":30.460,"GbpPrice":26.260,"RunType":"EP2","SystemLoad":2702.651},
{"EffectiveTime":"01-Oct-2016 04:30:00","EurPrice":30.460,"GbpPrice":26.260,"RunType":"EP2","SystemLoad":2694.620},{"EffectiveTime":"01-Oct-2016 05:00:00","EurPrice":30.510,"GbpPrice":26.300,"RunType":"EP2","SystemLoad":2718.430}]}'''
main_dict = json.loads(text)
for d in main_dict["Rows"]: # access "Rows" member
print(d)
'json.loads()'? –
これをすべての行にどのように適用するのですか? –