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;
답변을 작성하시기 전에 로그인 해주세요.