我正在尝试访问我的JSON的某个元素,通过React JS我在json上使用:Object.keys(field)[0]
并得到“punteggio”但我希望得到它的值,例如“7 ”。我如何访问这些数据?
"honours": [
{
"punteggio" : 7,
"serie" : "Serie A",
"tipo" : "icon-scudetto",
"anni" : "1926/1927 revocato, 1027/1928, 1942/1943, 1945/1946, 1947/1948"
},
{
"punteggio" : 4,
"serie" : "Serie B",
"tipo" : "icon-scudetto",
"anni" : "1958/1960, 1989/1990, 2000/2001, 2011/2012"
},
{
"punteggio" : 5,
"serie" : "Serie B",
"tipo" : "icon-coppaitalia",
"anni" : "1958/1960, 1989/1990, 2000/2001, 2011/2012"
}
]
答案 0 :(得分:0)
“punteggio” - 只是一个键,所以你可以像这样访问它的值
const key = Object.keys(field)[0];
const value = field[key];
答案 1 :(得分:0)