简体   繁体   English

在Postman中进行测试时,获取三重嵌套JSON对象的语法错误

[英]Getting Syntax Error for Triple nested JSON Object when test in Postman

I am getting a syntax error on line 16 denoting "bad string" 我在第16行收到语法错误,表示“错误字符串”

Not sure what is wrong here. 不知道这里出了什么问题。

{
    "username": "email",
    "password": "eagle",
    "firstName": "Cameron",
    "lastName": "Elliott",
    "phoneNumber": 1112223333,
    "photo": "What ever a photo looks like",
    "aboutMe": "Hi my name is Cameron Elliott, Your new surfing instructor!",
    "availability": {
        "monday": {
            "available": true,
            "day": "Monday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "tuesday": {
            "available": true,
            "day": "Tuesday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "wednesday": {
            "available": true,
            "day": "Wednesday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "thursday": {
            "available": true,
            "day": "Thursday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "friday": {
            "available": true,
            "day": "Friday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "saturday": {
            "available": true,
            "day": "Saturday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
        "sunday": {
            "available": true,
            "day": "Sunday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        },
    },
}

I would love to know what I'm doing wrong here. 我很想知道我在这里做错了什么。 just stepping into setting up database schema and models so any info on whats wrong is awesome. 只需进入设置数据库架构和模型的步骤,那么关于出问题的任何信息都很棒。

For example, maybe using an array very an object or using different types of structuring. 例如,可能只使用一个数组作为对象,或者使用不同类型的结构。

At the first look, the JSON given to the question looks good. 乍一看,给该问题的JSON看起来不错。 However, there are few issues. 但是,问题很少。 To understand it, let's remove some data and make it simple. 为了理解它,让我们删除一些数据并使其简单。 So, here is the simple JSON that has issues. 因此,这里是存在问题的简单JSON。

{
    "username": "email",
    "password": "eagle",
    "firstName": "Cameron",
    "lastName": "Elliott",
    "phoneNumber": 1112223333,
    "photo": "What ever a photo looks like",
    "aboutMe": "Hi my name is Cameron Elliott, Your new surfing instructor!",
    "availability": {
        "monday": {
            "available": true,
            "day": "Monday",
            "startTime": [0900, 1400],
            "endTime": [1230, 1700],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"],
        }
    },
}

Issue 1: 问题1:
In JavaScript, if a number starts with a 0 that isn't immediately followed by a . 在JavaScript中,如果数字以0开头,则不会紧随其后. , it represents an octal, not a decimal number. ,它代表一个八进制数,而不是十进制数。 Thus you need to change the value of startTime and endTime . 因此,您需要更改startTimeendTime的值。 you can make it string or change the value. 您可以将其设置为字符串或更改值。 Here I'm changing it as string type 在这里,我将其更改为字符串类型

"startTime": ["0900", "1400"],
"endTime": ["1230", "1700"],

Issue 2: 问题2:
Remove comma at closing bracket of beaches 删除beaches右括号处的逗号

Error: Parse error on line 15:
...a Jolla Shores"],        }   },}
----------------------^
Expecting 'STRING', got '}'

Issue 3: 问题3:
Remove comma at closing bracket of availability availability右括号中删除逗号

在此处输入图片说明

Final valid JSON 最终有效的JSON

{
    "username": "email",
    "password": "eagle",
    "firstName": "Cameron",
    "lastName": "Elliott",
    "phoneNumber": 1112223333,
    "photo": "What ever a photo looks like",
    "aboutMe": "Hi my name is Cameron Elliott, Your new surfing instructor!",
    "availability": {
        "monday": {
            "available": true,
            "day": "Monday",
            "startTime": ["0900", "1400"],
            "endTime": ["1230", "1700"],
            "beaches": ["Ocean Beach", "South Mission Beach", "Mission Beach", "Pacific Beach", "Tourmoline", "La Jolla Shores"]
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM