Parsing a complicated array with GetJSON Jquery

Posted by Ozaki on Stack Overflow See other posts from Stack Overflow or by Ozaki
Published on 2010-04-29T05:37:48Z Indexed on 2010/04/29 5:47 UTC
Read the original article Hit count: 419

Filed under:
|
|
|
|

TLDR:

  1. Started with this question simplified it after got some of it working and continuing it here.
  2. I need to 'GET' the JSON array
  3. Format it correctly and for each within the array place it in the corresponding DIV.
  4. ??
  5. It works.

This is a followup from this question to simplify and continue.

I need to some complicated JSON data from an array. With it I need the title and it's value. The reason why I am doing this is because I will know what the array is called but not the data that is being generated inside it.

Lets say this new array looks as follows:

{"Days":
["Sunday":"10.00", "Monday":"12.00", "Tuesday":"09.00", "Wednesday":"10.00", "Thursday":"02.00", "Friday":"05.00", "Saturday":"08.00"]
}

I would need it to get Sunday & 10.00 as well as the same for all of the others.

My code to parse this at the moment is as follows:

$.getJSON(url,
    function(data){
      $.each(data, function(i,item){
      $('.testfield').append('<p>' + item + '</p>');
      });
    });

Without the added times on each date it will parse the data as follows:

Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday

With the times added to the days in the array Firebug no longer recognizes it as a JSON string. So I am guessing I have formatted something wrong here. Also, I need each day & time to be on a new line I thought that

$('.testfield').append('<p>' + item + '</p>' + '<br />');

Would have applied each one to a new line but that did not work.

  1. How do I get each day or item to be on a new line?
  2. How do I get the $getjson to parse the data correctly day and its value, into a div?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JSON