I want to create a JSON array which includes two elements. I wrote the following code:
var myArray2 = [
{
"nome": "Aldo Maria",
"indirizzo": "Viale Europa 1",
"telefono": "3397889034"
},
{
nome: "Maria13",
indirizzo: "Viale Europa 1",
telefono: "3397889034"
}
];
I'm trying to parse it by using the Chrome extension Json Viewer Awesome but I get the error
Failed to parse invalid JSON format
On the other hand, I don't get this error while inserting a single element in the array, as in the snippet below:
{
"myArray2": [
{
"message": "Welcome to Awesome JSON Viewer.",
"status_code": 200
}
]
}
Yes because your keys doesn't contains double quotes ("")
for the part of json. The valid JSON would be
In JSON, keys must be strings, written with double quotes.
[{
"nome": "Aldo Maria",
"indirizzo": "Viale Europa 1",
"telefono": "3397889034"
},
{
"nome": " Maria13",
"indirizzo": "Viale Europa 1",
"telefono": "3397889034"
}
]
In JavaScript, keys can be strings, numbers, or identifier names.See example
{ name:"John" }
For reference look
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.