假设我有一个如下所示的 JSON 文档/JavaScript 对象:
var animal = {
"squirrel": "Squirrels belong to a large family of small or medium-sized rodents called the Sciuridae."
}
在 JavaScript 中,这会发生:
console.log(animal.squirrel) //Squirrels belong to a large family of small or medium-sized rodents called the Sciuridae
假设我想将rank
对象添加到:
var animal = {
"squirrel": {
"rank": {
"Kingdom": "Animalia",
"Phylum": "Chordata",
"Class": "Mammalia",
"Order": "Rodentia",
"Suborder": "Sciuromorpha",
"Family": "Sciuridae"
}
}
}
排名可以像这样访问:
animal.squirrel.rank
但我仍然希望对象的顶层animal.squirrel
是包含上述句子的字符串。
这可能吗?