<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>JSON parsing</title>
<style> </style>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(function(){
$.ajax({
url: "http://localhost:8080/weather/ForecastGrib.json",
dataType: "json",
success: function(data){
$.each(data, function(index, item){
alert(item.key + ":" +item.value + ":" +item.age);
})
}
})
})
</script>
</head>
<body>
<p>test<p>
</body>
</html>
이렇게 하면
[{"key":"11", "value" : "lang", "age" : "25"}
,{"key":"22", "value" : "math", "age" : "22"}
,{"key":"37", "value" : "engl", "age" : "28"}]
이런 형식의 Json파일은 불러 올 수 있겠는데 기상청 API에서 가져온 json파일은
{"response":{"header":{"resultCode":"0000","resultMsg":"OK"},"body":{"items":{"item":
[{"baseDate":20161202,"baseTime":"0900","category":"LGT","nx":53,"ny":38,"obsrValue":0}
,{"baseDate":20161202,"baseTime":"0900","category":"PTY","nx":53,"ny":38,"obsrValue":0}
,{"baseDate":20161202,"baseTime":"0900","category":"REH","nx":53,"ny":38,"obsrValue":55}
,{"baseDate":20161202,"baseTime":"0900","category":"VEC","nx":53,"ny":38,"obsrValue":13}]
},"numOfRows":8,"pageNo":1,"totalCount":10}}}
이런 식으로 시작이 [{ 아니라 {"response"식으로 시작해서 어떻게 파일을 가져와야 하는지 모르겠습니다. body찾고 item찾은 다음 그 뒤에부터 읽도록 하는 형식으로 하는거 같은데 감을 못잡겠네요. 해결방안 알려주시면 감사하겠습니다. ajax말고 다른 방법으로 알려주셔도 됩니다!