скажем, у меня есть этот фрагмент данных:
{
"welcome": "This is Json data that helps see what happened around the world so far",
"2020": [
[{
"Title": "The Duke and Duchess of Sussex shocked both sides of the pond on Jan. 8 when they announced they were stepping down as “senior” royals.",
"Description": "Prince Harry and Meghan Markle quit royal family",
"Date": "Jan",
"Photo": "https://nypost.com/wp-content/uploads/sites/2/2020/08/queen-meghan-markle-prine-harry.jpg?quality=90&strip=all&w=1236",
"Country": "Uk",
"Title2": "COVID-19 pandemic",
"Description2": "The World Health Organization announced Jan. 9 that a deadly coronavirus had emerged in Wuhan, China. In a matter of months, the virus has spread across the globe to more than 20 million people, resulting in at least 751,000 deaths.",
"Date2": "Jan",
"Country2": "world wide"
}]
]
}
Как получить доступ [2020][2nd title]
?
Я сделал что-то вроде этого, но это не сработало:
data.2020[5]
Тоже не сработало :( @OwenKelvin
Ваш json
объект недействителен, укажите действительные JSON
данные
Каков ваш ожидаемый результат?
Я обновил его, извините за это! @ОуэнКелвин
Я хочу Title2
(пандемия COVID-19) @LahiruTennakoon
Вы можете просто решить проблему шаг за шагом
const data = {
"welcome": "This is Json data that helps see what happened around the world so far",
"2020": [
[{
"Title": "The Duke and Duchess of Sussex shocked both sides of the pond on Jan. 8 when they announced they were stepping down as “senior” royals.",
"Description": "Prince Harry and Meghan Markle quit royal family",
"Date": "Jan",
"Photo": "https://nypost.com/wp-content/uploads/sites/2/2020/08/queen-meghan-markle-prine-harry.jpg?quality=90&strip=all&w=1236",
"Country": "Uk",
"Title2": "COVID-19 pandemic",
"Description2": "The World Health Organization announced Jan. 9 that a deadly coronavirus had emerged in Wuhan, China. In a matter of months, the virus has spread across the globe to more than 20 million people, resulting in at least 751,000 deaths.",
"Date2": "Jan",
"Country2": "world wide"
}]
]
}
console.info(data[2020][0][0].Title2)
Вы можете получить доступ к свойствам, используя скобки, как показано ниже.
const data = {
"welcome": "This is Json data that helps see what happened around the world so far",
"2020": [
[{
"Title": "The Duke and Duchess of Sussex shocked both sides of the pond on Jan. 8 when they announced they were stepping down as “senior” royals.",
"Description": "Prince Harry and Meghan Markle quit royal family",
"Date": "Jan",
"Photo": "https://nypost.com/wp-content/uploads/sites/2/2020/08/queen-meghan-markle-prine-harry.jpg?quality=90&strip=all&w=1236",
"Country": "Uk",
"Title2": "COVID-19 pandemic",
"Description2": "The World Health Organization announced Jan. 9 that a deadly coronavirus had emerged in Wuhan, China. In a matter of months, the virus has spread across the globe to more than 20 million people, resulting in at least 751,000 deaths.",
"Date2": "Jan",
"Country2": "world wide"
}]
]
};
console.info(data[2020][0][0]['Title2']);
data[2020][1].Title
?