json 불러와서 출력하는 부분인데요.

json 불러와서 출력하는 부분인데요.

QA

json 불러와서 출력하는 부분인데요.

본문

{
    "result": {
        "message": "성공",
        "code": 9200,
        "requestUrl": "/weather/summary?version=1&lat=37.4930444&lon=127.0137737"
    },
    "common": {
        "alertYn": "Y",
        "stormYn": "N"
    },
    "weather": {
        "summary": [
            {
                "grid": {
                    "latitude": "37.4876400000",
                    "longitude": "126.9879200000",
                    "city": "서울",
                    "county": "서초구",
                    "village": "방배4동"
                },
                "yesterday": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_Y01"
                    },
                    "precipitation": {
                        "rain": "0.00",
                        "snow": "0.00"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "today": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_D01"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "tomorrow": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_M01"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "dayAfterTomorrow": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_M01"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "timeRelease": "2013-11-0717: 00: 00"
            }
        ]
    }
}



yesterday->sky->name 값을 출력하고 싶은데 잘 안되네요.

에고 어깨넘어로 배워서 군데군데 막히네요.

고수님 좀 도와주세요. 고맙습니다.  

이 질문에 댓글 쓰기 :

답변 1


$json_str = '
{
    "result": {
        "message": "성공",
        "code": 9200,
        "requestUrl": "/weather/summary?version=1&lat=37.4930444&lon=127.0137737"
    },
    "common": {
        "alertYn": "Y",
        "stormYn": "N"
    },
    "weather": {
        "summary": [
            {
                "grid": {
                    "latitude": "37.4876400000",
                    "longitude": "126.9879200000",
                    "city": "서울",
                    "county": "서초구",
                    "village": "방배4동"
                },
                "yesterday": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_Y01"
                    },
                    "precipitation": {
                        "rain": "0.00",
                        "snow": "0.00"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "today": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_D01"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "tomorrow": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_M01"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "dayAfterTomorrow": {
                    "sky": {
                        "name": "맑음",
                        "code": "SKY_M01"
                    },
                    "temperature": {
                        "tmax": "15.10",
                        "tmin": "10.50"
                    }
                },
                "timeRelease": "2013-11-0717: 00: 00"
            }
        ]
    }
}';
$obj = json_decode($json_str);
 
echo $obj->weather->summary[0]->yesterday->sky->name;
답변을 작성하시기 전에 로그인 해주세요.
전체 82
QA 내용 검색

회원로그인

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