2017-04-05 10 views
0

こんにちは、私は次のような構造でJSONを解析しようとしています:私は私ができませんでしたJSONを解析初心者ですのでjsonから次の2つのリストを取得するには?

{"Question":["what is this?","this is another question"], "Topic": ["Web pages","another topic"]} 

私は2つのリスト、

questions=["what is this?","this is another question"] 
topics=["Web pages","another topic"] 

を取得したいと思い試してみました:

>>> with open('stack.json','r') as f: 
...  data = json.load(f) 
... 
>>> for element in data: 
...  print(element) 
... 

は、しかし、私はちょうど得た:

Question 
Topic 

私は前の2つのリストを取得するためにサポートを感謝したいと思います。

data.valuesの要素のための
['what is this?', 'this is another question'] 
['Web pages', 'another topic'] 
+0

'()::' – AChampion

答えて

1

あなたは

import json 

with open('stack.json','r') as f: 
    data = json.load(f) 
    questions=data["Question"] 
    topics=data['Topic'] 
    print(questions) 
    print(topics) 

が出力辞書のキーを使用しなければならない要素を取得するにはjsonsを解析する。

+0

おかげで多くは今、私はどのように理解し – neo33

+0

私の答えが役に立ったら、それを正しいものとしてマークしてください。 – eyllanesc

関連する問題