繁体   English   中英

如何创建具有多个属性/属性的单个JSON对象?

[英]How do I create a single JSON object with multiple attributes/properties?

我需要创建一个名为args的JSON对象,它具有2个属性/属性,key1和key2。

目前这是我所拥有的,但无法正确解析...

var args:{
   'key1': $scope.args.users, 
   'key2': 'http://financialsystems.sungard.com/'
}

其中$ scope.args.users是一个数组:

$scope.args.users = [
        {id: '1', firstName: 'Geraldine', lastName: 'Roberts', email: 'geraldine.roberts@email.com', country: 'South Africa'},
        {id: '2', firstName: 'Walter', lastName: 'Mitty', email: 'w.mitty@email.com', country: 'USA'}
    ];

我要去哪里错了? 每个属性/属性周围是否应该有另一套花括号?

  1. 您不能使用标签启动JSON对象。 看来您周围缺少{}
  2. JSON中的属性名称必须是字符串。 args必须是"args"
  3. 字符串必须用" not '引号'key1'必须为"key1""key1"
  4. 您根本无法在JSON中使用变量

这样:

{
    "args": {
        "key1": [
            {
                "id": "1",
                "firstName": "Geraldine",
                "lastName": "Roberts",
                "email": "geraldine.roberts@email.com",
                "country": "South Africa"
            },
            {
                "id": "2",
                "firstName": "Walter",
                "lastName": "Mitty",
                "email": "w.mitty@email.com",
                "country": "USA"
            }
        ],
        "key2": "http://financialsystems.sungard.com/"
    }
}

替换:=

 var args = {
   'key1': $scope.args.users, 
   'key2': 'http://financialsystems.sungard.com/'
  };

暂无
暂无

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

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