【发布时间】:2019-12-03 15:27:00
【问题描述】:
I am trying to read a json and want the output in excel so am trying to put dict in tabular format in excel.
**Code**
f = open(filename, 'r') #open json file
data = json.loads(f.read()) #load json
for s in data['quiz']: #finding 'quiz type in Json
Quiz_Type = s
print(Quiz_Type)
数据
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}
i want print(Quiz_Type) o\p as Sport only..
but instead im getting Sport and Math
我得到了 o/p:- 数学 NBA中哪一个是正确的球队名称?纽约公牛队||洛杉矶国王队||金州勇士队||休斯顿火箭队 休斯顿火箭队
数学 5 + 7 = ? 10||11||12||13 12 12 - 8 = ? 1||2||3||4 4
我需要运动来代替第一数学
【问题讨论】:
-
您的 JSON 似乎不完整。
-
是的,我现在已经编辑过了..