Display returned json/xml

122 views
Skip to first unread message

donkz2

unread,
Apr 21, 2014, 1:51:34 PM4/21/14
to metoffice...@googlegroups.com
Hi all,

Apologies for the novice question. But hope someone can help.

I am looking at displaying the returned json (or xml) into a webpage? 

Would someone be able to give me the heads up on how this is achieved.

As I understand it you cannot request/retrieve data cross domain?

I have the links which I need, I just need to know how to display so I can style etc.

Thanks in advance.
 

Chris Wood

unread,
Apr 22, 2014, 11:08:22 AM4/22/14
to metoffice...@googlegroups.com
jQuery has a getJSON() method, which is probably now the most straightforward way to parse the results: http://api.jquery.com/jquery.getjson/; the docs page has an example (which use the flickr api, but it should be easy to adapt it to your needs).

Chris

Graham Wright

unread,
Jun 24, 2014, 2:34:34 AM6/24/14
to metoffice...@googlegroups.com
Using JSON you need something like
 

$(function () {

var Key = 'XXXXXX';

var Croydon = '324152';

var url = 'http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/' + Croydon + '?res=daily&key=' + Key;

$.get(url, null, processDailyForecast);

});

function processDailyForecast(data) {

var details = '';

$.each(data.SiteRep.DV.Location.Period, function (name, Period) {

details += '<p>' + Period.value;

$.each(Period.Rep, function (name, value) {

if (value.$ == 'Day') {

details += '<p>' + value.$ + ' : ' + value.Dm + '</p>';

}

else{

details += '<p>' + value.$ + ' : ' + value.Nm + '</p>';

}

});

details += '</p>';

});

$('#dailyForecast').html(details);

}

 
Reply all
Reply to author
Forward
0 new messages