1
{
"2013\/02\/05":[                        
{"id":"84eb13cfed01764d9c401219faa56d53","colour":"#000000","category":"custom"}
],
}

I have used the jquery code given below.I am trying to access the date '2013/02/05' and the array elements like id ,colour and category of that date.

     $(document).ready(function(){
      var output = $("#changeBtn");
      $("#data").click(function(){
        $.getJSON("json_data.json",function(jd){
               var dates = jd.date;
               alert(dates);
                });
          });

1 Answer 1

1

The object returned is an associative array so you can access the property as follows:

$.getJSON("json_data.json",function(jd){
               var dates = jd["2013\/02\/05"][0].colour;
               alert(dates);
 });

JS Fiddle: http://jsfiddle.net/DLKfK/

On a side note, that is a pretty nasty object. I'm not sure why it needs to assign an array to the date property. If you have control over the object I would refactor it. One thing you should definitely refactor is the extra common after the array since this make the JSON invalid.

{
    "2013/02/05": [
        {
            "id": "84eb13cfed01764d9c401219faa56d53",
            "colour": "#000000",
            "category": "custom"
        }
    ], //this comma is invalid
} 
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks kevin.I am unable to access the colour object with that date format
It is an data for an event.On that particular date: the id,colour and category is being displayed in an array
@balaji Are you sure the object is coming back as you state in your question? I put that into the fiddle and the fiddle works.
If you log jd to the console does it show the object? Are you testing this in IE? That last comma after the array will break older versions of IE
/i logged to console.it doesnt retrun any object..I am trying it in the IE 9 version
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.