簡體   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