简体   繁体   English

简单的JSON Parse错误,不确定出了什么问题

[英]simple JSON Parse error, not sure what went wrong

I have this mock JSON data that I prepared in javascript that I was planning to use later but it seems when I run the project I get an error in the console as stated below. 我有我准备在JavaScript中准备的模拟JSON数据,打算稍后使用,但似乎在运行项目时在控制台中出现了如下所述的错误。

PS: the page is empty and currently there is only the script tag. PS:页面为空,当前只有脚本标签。 I want to get the JSON object ready before I do anything with it 我想在执行任何操作之前准备好JSON对象

Javascript: 使用Javascript:

var text = '{cinemaList: [{cinemaName: "Causeway Point",locationLat: 0,locationLong: 0,dateList: [{showDate: "Sep26, 1995",timeSlotList: [{showTime: "4.00 PM"},{showTime: "5.00 PM"}]}]},{cinemaName: "JEM"}]}';
var response = JSON.parse(text);
console.log(response);

Error: 错误:

SyntaxError: JSON Parse error: Expected '}'
parseTestTimeSlot.jsp:19
(anonymous function)TestTimeSlot.jsp:19

I don't see anything wrong with what I did. 我的所作所为没有错。 If anyone is kind enough to shine some light to my situation, it would be greatly appreciated ! 如果有人能照亮我的情况,将不胜感激! Thanks ! 谢谢 !

Well, your json has an invalid format. 好吧,您的json格式无效。 Use a tool like jsonlint to debug your json. 使用jsonlint之类的工具调试json。

Json has a very strict format. Json的格式非常严格。 In your case you don't have quotes around the keys, which is not valid. 在您的情况下,键周围没有引号,这是无效的。 Your correct json would be: 您正确的json是:

{
    "cinemaList": [
        {
            "cinemaName": "Causeway Point",
            "locationLat": 0,
            "locationLong": 0,
            "dateList": [
                {
                    "showDate": "Sep26, 1995",
                    "timeSlotList": [
                        {
                            "showTime": "4.00 PM"
                        },
                        {
                            "showTime": "5.00 PM"
                        }
                    ]
                }
            ]
        },
        {
            "cinemaName": "JEM"
        }
    ]
}

See json.org for some excellent graphs on how json is expected to be. 请参阅json.org,以获取一些有关json预期效果的出色图表。 The rules that are relevant here are: 这里相关的规则是:

object  -> {} | { members }
members -> pair | pair , members
pair    -> string : value
string  -> "" | " chars "

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

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