我怎样才能创建一个JSON对象数组?

时间:2018-06-08 16:37:11

标签: javascript json

每个对象代表不同的用户,每个用户有3个属性:loginid,password,realname。

以下是我所写的内容。这条线是否正确?

var user= [
    {"loginid":"email1@email.com", "password":1234, "realname":"A" };,
    {"loginid":"email2@email.com", "password":1234, "realname":"B" };,
    {"loginid":"email3@email.com", "password":1234, "realname":"C" };,
]

4 个答案:

答案 0 :(得分:0)

这是正确的,除了分号。

编辑: 实际上,我认为正确的方法是

{ "users": [
      {"loginid":"email1@email.com", "password":1234, "realname":"A" },
      {"loginid":"email2@email.com", "password":1234, "realname":"B" },
      {"loginid":"email3@email.com", "password":1234, "realname":"C" },
  ]
}

答案 1 :(得分:0)

像LGSon说的那样,你需要放弃;从每一行。你也可以定义字段namaes而不用" ",像这样:

  var user= [
      {loginid:"email1@email.com", password:1234, realname:"A" },
      {loginid:"email2@email.com", password:1234, realname:"B" },
      {loginid:"email3@email.com", password:1234, realname:"C" },
   ]

答案 2 :(得分:0)

我相信这就是你想要的:

 var user= [
      {loginid:"email1@email.com", password:1234, realname:"A"},
      {loginid:"email2@email.com", password:1234, realname:"B"},
      {loginid:"email3@email.com", password:1234, realname:"C"},
       ];

答案 3 :(得分:0)

这就是你如何创建数组对象JSON

    {
    "user": [{
            "loginid": "email1@email.com",
            "password": 1234,
            "realname": "A"
        },
        {
            "loginid": "email2@email.com",
            "password": 1234,
            "realname": "B"
        },
        {
            "loginid": "email3@email.com",
            "password": 1234,
            "realname": "C"
        }
    ]
}