1

I have some JSON Data like this:

[{"2015-02-10": ["00:00","00:30","01:00","01:30","02:00","02:30","03:00","03:30","04:00","04:30","05:00","05:30","06:00","06:30","07:00","07:30","12-00","12-30","13-00","13-30","18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00","22:30","23:00","23:30"]},{"2015-02-17": ["00:00","00:30","01:00","01:30","02:00","02:30","03:00","03:30","04:00","04:30","05:00","05:30","06:00","06:30","07:00","07:30","12-00","12-30","13-00","13-30","18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00","22:30","23:00","23:30"]}]

Now I parse it in Javascript and tried to access the values of a specific date:

var hours = $.parseJSON('JSON STRING ...');
var date = "2015-02-10";
console.log(hours[date]);

But I always get "undefined" and I really don't know how I can access this

1
  • The "JSON Data" you have is actually an Array, containing an object, containing an array. hours[0][date] Commented Feb 9, 2015 at 21:28

1 Answer 1

3

Your data is an array ([ ... ]) with an object inside it.

Try:

console.log(hours[0][date]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks i tried it before but as date is an dynamic value I don't know which index it has. So i changed the JSON structure to this: {"2015-02-10": ["00:00","00:30","01:00","01:30","02:00","02:30","03:00","03:30","04:00","04:30","05:00","05:30"],"2015-02-17": ["00:00","00:30"]} So i can access directly via key :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.