创建包含多个元素的数组时,无法识别JSON格式 [英] JSON format is not recognized when I create an array with more than one element

查看:196
本文介绍了创建包含多个元素的数组时,无法识别JSON格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个包含两个元素的JSON数组. 我写了以下代码:

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"
      }
    ];

我正在尝试使用Chrome扩展Json Viewer Awesome来解析它,但出现错误

I'm trying to parse it by using the Chrome extension Json Viewer Awesome but I get the error

无法解析无效的JSON格式

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
        }
    ]
}

推荐答案

是的,因为您的密钥不包含json部分的double quotes (""). 有效的JSON将是

Yes because your keys doesn't contains double quotes ("") for the part of json. The valid JSON would be

在JSON中,键必须是字符串,并用双引号引起来.

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"
    }
]

在JavaScript中,键可以是字符串,数字或标识符名称.请参见示例

In JavaScript, keys can be strings, numbers, or identifier names.See example

{ name:"John" }

供参考

此处

这篇关于创建包含多个元素的数组时,无法识别JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆