使用Javascript将新组插入JSON

问题描述 投票:-5回答:1

var module = {
  "code": "6COM9051",
  "name": "More Web Scripting",
  "cohort": "IT/JH/ITMB",
  "students": {
    "97xx08xx01": {
      "firstName": "Jo 1",
      "lastName": "Bloggs",
      "allocatedGroup": "690511"
    },
    "97xx08xx03": {
      "firstName": "Jo 2",
      "lastName": "Bloggs",
      "allocatedGroup": "690511"
    },
    "97xx08xx02": {
      "firstName": "Jo 3",
      "lastName": "Bloggs",
      "allocatedGroup": "690513"
    },
    "97xx08xx06": {
      "firstName": "Joe 1",
      "lastName": "Bliggs",
      "allocatedGroup": "690513"
    },
    "97xx08xx05": {
      "firstName": "Joe 2",
      "lastName": "Bliggs",
      "allocatedGroup": "690511"
    },
    "97xx08xx04": {
      "firstName": "Joe 3",
      "lastName": "Bliggs",
      "allocatedGroup": "690513"
    },
  },
  "groups": {
    "690511": {
      "name": "Tutorial 1",
      "members": ["97xx08xx01", "97xx08xx05", "97xx08xx03"]
    },
    "690513": {
      "name": "Tutorial 2",
      "members": ["97xx08xx04", "97xx08xx02", "97xx08xx06"]
    }
  }
}
javascript json
1个回答
-1
投票

你可以只分配值,

modules.groups["<group key>"] = {
    "name": "Tutorial 123",
    "members": ["97xx08xx01", "97xx08xx05", "97xx08xx03"]
}

PS:我认为你是stackoverflow的新手。虽然我回答了这个问题,但这个社区不鼓励这类问题。如何将属性添加到JSON是一个非常基本的东西,可以在百万个教程中解释,并且可能在几年前就在stackoverflow上回答。在你寻求帮助之前做好功课。

© www.soinside.com 2019 - 2024. All rights reserved.