Json导入错误

时间:2017-10-14 11:51:13

标签: python json

我有一个json文件将我的代码链接到并保存但现在在我的程序中收到错误Error Img 这是因为我修改了我的.json文件。在我的json文件中,我有一个25个学生的迷你数据库,我首先在我的json文件中遗漏了一些东西,但我修复了那个我上面的错误

任何帮助都会受到影响,因为这非常重要

非常感谢Luke

CODE:

import json
from pprint import pprint 

with open('studentDetails.json') as data_file:    
    data = json.load(data_file)

signedIn = False
FormUsername = "Mr Leeman"
FormPassword = "abc12345"

print("Please Enter Username")
usernameInput=input()


print("Please Enter Password")
passwordInput=input()

if usernameInput == FormUsername:

    if passwordInput == FormPassword:
        print("signedIn!")
        signedIn = True

if signedIn == True:
        print("1. Enter Students ID Number")
        print("2. Add A Student")


        print("Enter The Number Of The Option Eg: 1 or 2")
        menuNumber=input()

        if menuNumber == "1":
                print("\n" * 10)
                print("Please Enter A students ID Number")

                IDNumInput=input()



                if IDNumInput == data["studentDetails"][0]["id"]:        
                        print("ID Number: ",data["studentDetails"][0]["id"])
                        print("Surname: ",data["studentDetails"][0]["surname"])
                        print("Forename: ",data["studentDetails"][0]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][0]["dob"])
                        print("Home Address: ",data["studentDetails"][0]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][0]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][0]["gen"])
                        print("Tutor Group: ",data["studentDetails"][0]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][0]["SchlEmail"])

                if IDNumInput == data["studentDetails"][1]["id"]:
                        print("ID Number: ",data["studentDetails"][1]["id"])
                        print("Surname: ",data["studentDetails"][1]["surname"])
                        print("Forename: ",data["studentDetails"][1]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][1]["dob"])
                        print("Home Address: ",data["studentDetails"][1]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][1]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][1]["gen"])
                        print("Tutor Group: ",data["studentDetails"][1]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][1]["SchlEmail"])

                if IDNumInput == data["studentDetails"][2]["id"]:
                        print("ID Number: ",data["studentDetails"][2]["id"])
                        print("Surname: ",data["studentDetails"][2]["surname"])
                        print("Forename: ",data["studentDetails"][2]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][2]["dob"])
                        print("Home Address: ",data["studentDetails"][2]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][2]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][2]["gen"])
                        print("Tutor Group: ",data["studentDetails"][2]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][2]["SchlEmail"])

                if IDNumInput == data["studentDetails"][3]["id"]:
                        print("ID Number: ",data["studentDetails"][3]["id"])
                        print("Surname: ",data["studentDetails"][3]["surname"])
                        print("Forename: ",data["studentDetails"][3]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][3]["dob"])
                        print("Home Address: ",data["studentDetails"][3]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][3]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][3]["gen"])
                        print("Tutor Group: ",data["studentDetails"][3]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][3]["SchlEmail"])

                if IDNumInput == data["studentDetails"][4]["id"]:
                        print("ID Number: ",data["studentDetails"][4]["id"])
                        print("Surname: ",data["studentDetails"][4]["surname"])
                        print("Forename: ",data["studentDetails"][4]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][4]["dob"])
                        print("Home Address: ",data["studentDetails"][4]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][4]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][4]["gen"])
                        print("Tutor Group: ",data["studentDetails"][4]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][4]["SchlEmail"])

                if IDNumInput == data["studentDetails"][5]["id"]:
                        print("ID Number: ",data["studentDetails"][5]["id"])
                        print("Surname: ",data["studentDetails"][5]["surname"])
                        print("Forename: ",data["studentDetails"][5]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][5]["dob"])
                        print("Home Address: ",data["studentDetails"][5]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][5]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][5]["gen"])
                        print("Tutor Group: ",data["studentDetails"][5]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][5]["SchlEmail"])

                if IDNumInput == data["studentDetails"][6]["id"]:
                        print("ID Number: ",data["studentDetails"][6]["id"])
                        print("Surname: ",data["studentDetails"][6]["surname"])
                        print("Forename: ",data["studentDetails"][6]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][6]["dob"])
                        print("Home Address: ",data["studentDetails"][6]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][6]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][6]["gen"])
                        print("Tutor Group: ",data["studentDetails"][6]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][6]["SchlEmail"])

                if IDNumInput == data["studentDetails"][7]["id"]:
                        print("ID Number: ",data["studentDetails"][7]["id"])
                        print("Surname: ",data["studentDetails"][7]["surname"])
                        print("Forename: ",data["studentDetails"][7]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][7]["dob"])
                        print("Home Address: ",data["studentDetails"][7]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][7]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][7]["gen"])
                        print("Tutor Group: ",data["studentDetails"][7]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][7]["SchlEmail"])

                if IDNumInput == data["studentDetails"][8]["id"]:
                        print("ID Number: ",data["studentDetails"][8]["id"])
                        print("Surname: ",data["studentDetails"][8]["surname"])
                        print("Forename: ",data["studentDetails"][8]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][8]["dob"])
                        print("Home Address: ",data["studentDetails"][8]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][8]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][8]["gen"])
                        print("Tutor Group: ",data["studentDetails"][8]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][8]["SchlEmail"])

                if IDNumInput == data["studentDetails"][9]["id"]:
                        print("ID Number: ",data["studentDetails"][9]["id"])
                        print("Surname: ",data["studentDetails"][9]["surname"])
                        print("Forename: ",data["studentDetails"][9]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][9]["dob"])
                        print("Home Address: ",data["studentDetails"][9]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][9]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][9]["gen"])
                        print("Tutor Group: ",data["studentDetails"][9]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][9]["SchlEmail"])

                if IDNumInput == data["studentDetails"][10]["id"]:
                        print("ID Number: ",data["studentDetails"][10]["id"])
                        print("Surname: ",data["studentDetails"][10]["surname"])
                        print("Forename: ",data["studentDetails"][10]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][10]["dob"])
                        print("Home Address: ",data["studentDetails"][10]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][10]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][10]["gen"])
                        print("Tutor Group: ",data["studentDetails"][10]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][10]["SchlEmail"])

                if IDNumInput == data["studentDetails"][11]["id"]:
                        print("ID Number: ",data["studentDetails"][11]["id"])
                        print("Surname: ",data["studentDetails"][11]["surname"])
                        print("Forename: ",data["studentDetails"][11]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][11]["dob"])
                        print("Home Address: ",data["studentDetails"][11]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][11]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][11]["gen"])
                        print("Tutor Group: ",data["studentDetails"][11]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][11]["SchlEmail"])

                if IDNumInput == data["studentDetails"][12]["id"]:
                        print("ID Number: ",data["studentDetails"][12]["id"])
                        print("Surname: ",data["studentDetails"][12]["surname"])
                        print("Forename: ",data["studentDetails"][12]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][12]["dob"])
                        print("Home Address: ",data["studentDetails"][12]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][12]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][12]["gen"])
                        print("Tutor Group: ",data["studentDetails"][12]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][12]["SchlEmail"])


                if IDNumInput == data["studentDetails"][13]["id"]:
                        print("ID Number: ",data["studentDetails"][13]["id"])
                        print("Surname: ",data["studentDetails"][13]["surname"])
                        print("Forename: ",data["studentDetails"][13]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][13]["dob"])
                        print("Home Address: ",data["studentDetails"][13]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][13]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][13]["gen"])
                        print("Tutor Group: ",data["studentDetails"][13]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][13]["SchlEmail"])

                if IDNumInput == data["studentDetails"][14]["id"]:
                        print("ID Number: ",data["studentDetails"][14]["id"])
                        print("Surname: ",data["studentDetails"][14]["surname"])
                        print("Forename: ",data["studentDetails"][14]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][14]["dob"])
                        print("Home Address: ",data["studentDetails"][14]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][14]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][14]["gen"])
                        print("Tutor Group: ",data["studentDetails"][14]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][14]["SchlEmail"])

                if IDNumInput == data["studentDetails"][15]["id"]:
                        print("ID Number: ",data["studentDetails"][15]["id"])
                        print("Surname: ",data["studentDetails"][15]["surname"])
                        print("Forename: ",data["studentDetails"][15]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][15]["dob"])
                        print("Home Address: ",data["studentDetails"][15]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][15]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][15]["gen"])
                        print("Tutor Group: ",data["studentDetails"][15]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][15]["SchlEmail"])

                if IDNumInput == data["studentDetails"][16]["id"]:
                        print("ID Number: ",data["studentDetails"][16]["id"])
                        print("Surname: ",data["studentDetails"][16]["surname"])
                        print("Forename: ",data["studentDetails"][16]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][16]["dob"])
                        print("Home Address: ",data["studentDetails"][16]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][16]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][16]["gen"])
                        print("Tutor Group: ",data["studentDetails"][16]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][16]["SchlEmail"])

                if IDNumInput == data["studentDetails"][17]["id"]:
                        print("ID Number: ",data["studentDetails"][17]["id"])
                        print("Surname: ",data["studentDetails"][17]["surname"])
                        print("Forename: ",data["studentDetails"][17]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][17]["dob"])
                        print("Home Address: ",data["studentDetails"][17]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][17]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][17]["gen"])
                        print("Tutor Group: ",data["studentDetails"][17]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][17]["SchlEmail"])

                if IDNumInput == data["studentDetails"][18]["id"]:
                        print("ID Number: ",data["studentDetails"][18]["id"])
                        print("Surname: ",data["studentDetails"][18]["surname"])
                        print("Forename: ",data["studentDetails"][18]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][18]["dob"])
                        print("Home Address: ",data["studentDetails"][18]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][18]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][18]["gen"])
                        print("Tutor Group: ",data["studentDetails"][18]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][18]["SchlEmail"])

                if IDNumInput == data["studentDetails"][19]["id"]:
                        print("ID Number: ",data["studentDetails"][19]["id"])
                        print("Surname: ",data["studentDetails"][19]["surname"])
                        print("Forename: ",data["studentDetails"][19]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][19]["dob"])
                        print("Home Address: ",data["studentDetails"][19]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][19]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][19]["gen"])
                        print("Tutor Group: ",data["studentDetails"][19]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][19]["SchlEmail"])

                if IDNumInput == data["studentDetails"][20]["id"]:
                        print("ID Number: ",data["studentDetails"][20]["id"])
                        print("Surname: ",data["studentDetails"][20]["surname"])
                        print("Forename: ",data["studentDetails"][20]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][20]["dob"])
                        print("Home Address: ",data["studentDetails"][20]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][20]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][20]["gen"])
                        print("Tutor Group: ",data["studentDetails"][20]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][20]["SchlEmail"])


                if IDNumInput == data["studentDetails"][21]["id"]:
                        print("ID Number: ",data["studentDetails"][21]["id"])
                        print("Surname: ",data["studentDetails"][21]["surname"])
                        print("Forename: ",data["studentDetails"][21]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][21]["dob"])
                        print("Home Address: ",data["studentDetails"][21]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][21]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][21]["gen"])
                        print("Tutor Group: ",data["studentDetails"][21]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][21]["SchlEmail"])

                if IDNumInput == data["studentDetails"][22]["id"]:
                        print("ID Number: ",data["studentDetails"][22]["id"])
                        print("Surname: ",data["studentDetails"][22]["surname"])
                        print("Forename: ",data["studentDetails"][22]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][22]["dob"])
                        print("Home Address: ",data["studentDetails"][22]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][22]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][22]["gen"])
                        print("Tutor Group: ",data["studentDetails"][22]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][22]["SchlEmail"])

                if IDNumInput == data["studentDetails"][23]["id"]:
                        print("ID Number: ",data["studentDetails"][23]["id"])
                        print("Surname: ",data["studentDetails"][23]["surname"])
                        print("Forename: ",data["studentDetails"][23]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][23]["dob"])
                        print("Home Address: ",data["studentDetails"][23]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][23]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][23]["gen"])
                        print("Tutor Group: ",data["studentDetails"][23]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][23]["SchlEmail"])

                if IDNumInput == data["studentDetails"][24]["id"]:
                        print("ID Number: ",data["studentDetails"][24]["id"])
                        print("Surname: ",data["studentDetails"][24]["surname"])
                        print("Forename: ",data["studentDetails"][24]["forename"])
                        print("Date Of Birth: ",data["studentDetails"][24]["dob"])
                        print("Home Address: ",data["studentDetails"][24]["Address"])
                        print("Home Phone Number: ",data["studentDetails"][24]["PhoneNum"])
                        print("Gender: ",data["studentDetails"][24]["gen"])
                        print("Tutor Group: ",data["studentDetails"][24]["TutorGroup"])
                        print("School Email: ",data["studentDetails"][24]["SchlEmail"])

1 个答案:

答案 0 :(得分:0)

听起来你的json文件中有拼写错误。

尝试使用像JSON online validator之类的东西,然后放下你的json来寻找错误。