Got the simplified array working see below
Following up on the complicated array to parse see here.
TLDR: Want to get each heading from an array and insert it into a div without knowing what is inside the div using Jquery - getJSON.
Edit: The data is coming from a piece of software that is outputting the JSON string every couple of seconds with new data, so I need to pull the array of data within "d" as in the example below. So i should get "Title" & "034324324"etc for each.
Edit2 Updated code to match mine exactly..
I have JSON array lets say:
{
"Days":
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
}
And I want to parse it as for each "title" to insert it into a div.
Trying along the lines of
function getdata() {
31 $.ajaxSetup ({ cache: false}); //<!-- Stops IE from caching data //-->
32
33 $.getJSON(testurl, function(data) {
34 $.each(data.days, function(i,item){
35 $('#testfield').append('<p>' + item + '</p>');
36
37 });
38 });
to no avail.
I am using Getjson in other places but in cases where I know what request I am making. e.g:
$('#name').html(data.Projectname);
Which is all working perfectly fine but in this case I need to get the details out of the array without knowing what is inside the array I'm sure there is something simple that I'm missing here or doing wrong ^^.
The JSON I have currently been working with looks like :
{"Projectname":"ertyofhj","Projectid":"aqwertyuqw","Projecttitle":"ertyofhj"}
The array was just a way to look out pulling out the data without knowing what was inside the array.
I just keep adding more. Debugging firebug or IE's debugger(Aargh) it will hit
33 $.getJSON(testurl, function(data) {
then
38 });
completely skipping
34 $.each(data.days, function(i,item){
-The GET request fires fine and returns the correct JSON string. But now it will not fill the $.each, or even if I specifically ask for a certain string.
On note of above Firebug is also telling me that it isn't formatted as JSON?
Changed the original JSON string to something simpler.(Days of the week) as is days of the week will load. So I am getting somewhere. But I need to be able to call a more complex array. For example (using the days) each day has a specific time on it that I need to display as well also each day should be on a new line tried adding in a " + '< br />' but that doesn't work either. Displayed in an array such as:
{"Days":
["Sunday":"10.00", "Monday":"12.00", "Tuesday":"09.00", "Wednesday":"10.00", "Thursday":"02.00", "Friday":"05.00", "Saturday":"08.00"]
}
And I need to pull Dayname & time for all.