FreeCodeCampChina / freecodecamp.cn

FCC China open source codebase and curriculum. Learn to code and help nonprofits.
https://fcc.asia/
Other
37.06k stars 1.38k forks source link

JSON结构是否应该是由{}包围而不是由[]包围? #164

Closed FuguDream closed 7 years ago

FuguDream commented 7 years ago

Challenge Accessing Nested Arrays in JSON has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

// Setup
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = myPlants[1].list[1]; // Change this line
S1ngS1ng commented 7 years ago

myPlants 是一个符合 JSON 格式的数组。题目中的这个写法才是标准写法。 如果最外面的 [] 换成 {},那么里面是不可能有两个 Object 的。

请看下这个官方链接,"JSON is built on two structures:" 这一段,题目中给出的这个形式符合第二种情况