Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

JavaScript and Json issue

[Update] I Have chosen to go with the database now and make a new collection for each command, it will then collect all the users that use the command.

Does anyone know how I can get multiple arrays in my Json file, I have 3 slash commands on discord that I a trying to collect data from, However when I use to command it just updates the current array in the Json file, I would like to either get all the uses of each command. So that then I can import the Json files to Mongodb.

I am new to JavaScript and using Mongodb so I am still learning so I would really appreciate all the help I can get below I will provide my code samples so you can see if I am doing something wrong.

Example of what I want to achieve

{
  "id": "281185483717869569",
  "command": "architect",
  "name": "UKzs",
  "description": [
    {
      "value": "569",
      "name": "x"
    },
    {
      "value": "663",
      "name": "y"
    },
{ 
  "id": "281185483717869569",
  "command": "duke",
  "name": "UKzs",
  "description": [
    {
      "value": "123",
      "name": "x"
    },
    {
      "value": "123",
      "name": "y"
    }
  ]
}
  ]
}
question from:https://stackoverflow.com/questions/65946254/javascript-and-json-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

My apologies for answering with a question. But does "...how I can get multiple arrays in my Json file..." mean "how can I nest arrays in JSON?" Is what you want to know is how to define a JSON array within another JSON array?

If that's what sought, it's:

[
  {
    "id": "281185483717869569",
    "command": "architect",
    "name": "UKzs",
    "array-within-array": [1,2,3, ["one", "two", "three"]],
    "description": [
      {
        "value": "123",
        "name": "x"
      },
      {
        "value": "123",
        "name": "y"
      }
    ]
  }
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...