Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  131] [ 7]  / answers: 1 / hits: 60119  / 12 Years ago, fri, june 1, 2012, 12:00:00
$.getJSON('http://23.21.128.153:3000/api/v1/holidays', function(data){
alert(this: + data.holiday[0].name);
});


I'm trying to access the name attribute of the first element of my JSON response but without success, can anyone tell me what I'm doing wrong.


More From » json

 Answers
29

Try this:



data[0].holiday.name


The data looks like this:



[
{
holiday:{
id:1,
date:2012-05-01,
name:Dia del trabajo,
description:,
country_id:1,
moved_date:2012-04-30
}
},
{
holiday:{...}
},
...]


So, you need to select the first element from the main array (data[0]), then get its holiday property (data[0].holiday), and then get its name property.


[#85225] Thursday, May 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elishaannac

Total Points: 28
Total Questions: 97
Total Answers: 101

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
elishaannac questions
Sun, Dec 5, 21, 00:00, 3 Years ago
Mon, Jun 14, 21, 00:00, 3 Years ago
Mon, Jul 22, 19, 00:00, 5 Years ago
Mon, Jul 8, 19, 00:00, 5 Years ago
;