【问题标题】:how to print first word of dict of json?如何打印json的dict的第一个单词?
【发布时间】: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 似乎不完整。
  • 是的,我现在已经编辑过了..

标签: python json printing


【解决方案1】:

您需要使用像 xlsxwriter 这样的库来写回 excel 格式。这个库有全面的文档:

https://xlsxwriter.readthedocs.io/

【讨论】:

  • 我不认为他正在寻找与保存或做与 excel 相关的事情的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-05
  • 2020-02-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多