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.
PS: the page is empty and currently there is only the script tag. I want to get the JSON object ready before I do anything with it
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. Use a tool like jsonlint to debug your json.
Json has a very strict format. In your case you don't have quotes around the keys, which is not valid. Your correct json would be:
{
"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. The rules that are relevant here are:
object -> {} | { members }
members -> pair | pair , members
pair -> string : value
string -> "" | " chars "
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.