我有一个从API端点接收到的以下JSON对象,如何访问该对象的description属性-“ description”:“ Dorian Market 1”?
let markets = {
"result":[
{
"townId" : "MEBD",
"storeId" : "1",
"address" : "Presernova 1",
"description" : "Dorian Market 1",
"minOrderValue" : "500",
"notes" : ""
}
,
{
"townId" : "MEBD",
"storeId" : "1",
"address" : "Presernova 2",
"description" : "Dorian Market 2 ",
"minOrderValue" : "500",
"notes" : ""
}
]
}
这是正确的方法吗? market.result [0] .description,这是正确的方法吗?
答案 0 :(得分:1)
是的,访问description
数组第一个元素的result
属性的正确方法是使用markets.result[0].description
。
let markets = {
"result":[
{
"townId" : "MEBD",
"storeId" : "1",
"address" : "Presernova 1",
"description" : "Dorian Market 1",
"minOrderValue" : "500",
"notes" : ""
},
{
"townId" : "MEBD",
"storeId" : "1",
"address" : "Presernova 2",
"description" : "Dorian Market 2 ",
"minOrderValue" : "500",
"notes" : ""
}
]
};
console.log(markets.result[0].description)