JSON 파싱 좀 알려주세요.

JSON 파싱 좀 알려주세요.

QA

JSON 파싱 좀 알려주세요.

본문

{"response":{"header":{"resultCode":"00","resultMsg":"NORMAL_SERVICE"},"body":{"dataType":"JSON","items":{"item":[{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2200","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2300","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240425","fcstTime":"0000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240425","fcstTime":"0100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2200","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2300","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240425","fcstTime":"0000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240425","fcstTime":"0100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2000","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2100","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2200","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2300","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240425","fcstTime":"0000","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240425","fcstTime":"0100","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2000","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2100","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2200","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2300","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240425","fcstTime":"0000","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240425","fcstTime":"0100","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2000","fcstValue":"14","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2100","fcstValue":"14","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2200","fcstValue":"12","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2300","fcstValue":"12","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240425","fcstTime":"0000","fcstValue":"11","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240425","fcstTime":"0100","fcstValue":"10","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2000","fcstValue":"75","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2100","fcstValue":"80","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2200","fcstValue":"80","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2300","fcstValue":"85","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240425","fcstTime":"0000","fcstValue":"85","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240425","fcstTime":"0100","fcstValue":"90","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2000","fcstValue":"2.8","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2100","fcstValue":"2.5","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2200","fcstValue":"2.3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2300","fcstValue":"1.9","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240425","fcstTime":"0000","fcstValue":"1.5","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240425","fcstTime":"0100","fcstValue":"1.3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2000","fcstValue":"-0.2","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2200","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2300","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240425","fcstTime":"0000","fcstValue":"-0.1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240425","fcstTime":"0100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2000","fcstValue":"277","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2100","fcstValue":"272","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2200","fcstValue":"269","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2300","fcstValue":"274","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240425","fcstTime":"0000","fcstValue":"277","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240425","fcstTime":"0100","fcstValue":"274","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2000","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2100","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2200","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2300","fcstValue":"2","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240425","fcstTime":"0000","fcstValue":"2","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240425","fcstTime":"0100","fcstValue":"1","nx":88,"ny":98}]},"pageNo":1,"numOfRows":1000,"totalCount":60}}}

fcstTime 1900시 LGT, PTY, RN1 ... 항목을 보여주고

fcstTime 2000시 LGT, PTY, RN1 ... 항목을 보여주고

fcstTime 2100시 LGT, PTY, RN1 ... 항목을 보여주려고 하는데요.

시간대별로 넘어오는게 아니라 파라메터별로 넘어와서 어떻게해야 할지 모르겠네요.

파싱해서 시간대별로 보여주는 방법 좀 알려주세요. 감사합니다.

 

이 질문에 댓글 쓰기 :

답변 1


<script>
var json = {"response":{"header":{"resultCode":"00","resultMsg":"NORMAL_SERVICE"},"body":{"dataType":"JSON","items":{"item":[{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2200","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240424","fcstTime":"2300","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240425","fcstTime":"0000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"LGT","fcstDate":"20240425","fcstTime":"0100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2200","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240424","fcstTime":"2300","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240425","fcstTime":"0000","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"PTY","fcstDate":"20240425","fcstTime":"0100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2000","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2100","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2200","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240424","fcstTime":"2300","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240425","fcstTime":"0000","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"RN1","fcstDate":"20240425","fcstTime":"0100","fcstValue":"강수없음","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2000","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2100","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2200","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240424","fcstTime":"2300","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240425","fcstTime":"0000","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"SKY","fcstDate":"20240425","fcstTime":"0100","fcstValue":"1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2000","fcstValue":"14","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2100","fcstValue":"14","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2200","fcstValue":"12","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240424","fcstTime":"2300","fcstValue":"12","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240425","fcstTime":"0000","fcstValue":"11","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"T1H","fcstDate":"20240425","fcstTime":"0100","fcstValue":"10","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2000","fcstValue":"75","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2100","fcstValue":"80","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2200","fcstValue":"80","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240424","fcstTime":"2300","fcstValue":"85","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240425","fcstTime":"0000","fcstValue":"85","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"REH","fcstDate":"20240425","fcstTime":"0100","fcstValue":"90","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2000","fcstValue":"2.8","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2100","fcstValue":"2.5","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2200","fcstValue":"2.3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240424","fcstTime":"2300","fcstValue":"1.9","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240425","fcstTime":"0000","fcstValue":"1.5","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"UUU","fcstDate":"20240425","fcstTime":"0100","fcstValue":"1.3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2000","fcstValue":"-0.2","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2200","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240424","fcstTime":"2300","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240425","fcstTime":"0000","fcstValue":"-0.1","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VVV","fcstDate":"20240425","fcstTime":"0100","fcstValue":"0","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2000","fcstValue":"277","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2100","fcstValue":"272","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2200","fcstValue":"269","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240424","fcstTime":"2300","fcstValue":"274","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240425","fcstTime":"0000","fcstValue":"277","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"VEC","fcstDate":"20240425","fcstTime":"0100","fcstValue":"274","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2000","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2100","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2200","fcstValue":"3","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240424","fcstTime":"2300","fcstValue":"2","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240425","fcstTime":"0000","fcstValue":"2","nx":88,"ny":98},{"baseDate":"20240424","baseTime":"1930","category":"WSD","fcstDate":"20240425","fcstTime":"0100","fcstValue":"1","nx":88,"ny":98}]},"pageNo":1,"numOfRows":1000,"totalCount":60}}};
 
var item_by_fcstTime = {};
json.response.body.items.item.forEach((data) => {
    var k = data.fcstTime;
    if (item_by_fcstTime[k] == null) {
        item_by_fcstTime[k] = [];
    }
    var fcstTime = Number(k);
    switch (fcstTime) {
    case 1900:
        if (['SKY','T1H'].includes(data.category) == true) {
            break;
        }
        item_by_fcstTime[k].push(data);
        break;
    case 2000:
        if (['SKY','T1H','REH','UUU'].includes(data.category) == true) {
            break;
        }
        item_by_fcstTime[k].push(data);
        break;
    case 2100:
        if (['SKY','T1H','REH','UUU','VVV','VEC','WSD'].includes(data.category) == true) {
            break;
        }
        item_by_fcstTime[k].push(data);
        break;
    default:
        item_by_fcstTime[k].push(data);
    }
});
 
console.log(item_by_fcstTime);
</script>
답변을 작성하시기 전에 로그인 해주세요.
전체 0
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT