私は実際にAPIを使用して、JSONデータを取得し、実際のHTMLファイルに投入して、結果をきれいに見せることにまったく慣れていません。
HTML/CSS/jQuery が得意です。しかし、これはjQueryの詳細ではないようです(私は基本を行うことができます)
これは、Weather Underground の API から取得した JSON データの例です。
"current_observation": {
"image": {
"url":"http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
},
"display_location": {
"full":"Bowling Green, KY",
"city":"Bowling Green",
"state":"KY",
"state_name":"Kentucky",
"country":"US",
"country_iso3166":"US",
"zip":"42101",
"latitude":"37.02899933",
"longitude":"-86.46366119",
"elevation":"154.00000000"
}
display_location
の中にあることがわかりますcurrent_observation
。
自分のウェブサイトでh1として引き出して表示full
したい(実際にはもっと情報を提供したいのですが、これを書き留めた後は残りを処理できるように感じます. )
だからここに私が現在持っているものがあります:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<section id="area"></section>
</body>
<script type="text/javascript">
$().ready(function(){
$.getJSON("http://api.wunderground.com/api/[MY API KEY]/conditions/q/autoip.json",
function(data){
$.each(data){
content = '<h1>' + json.current_observation.display_location.full + '</h1>';
$(content).appendTo("#area");
});
});
});
</script>
</html>
それは動作しません :-/
どんな助けも素晴らしいです。