object json decode
Copy
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/"));
로 ininfo.io에서 정보를 받아오고
Copy
echo $details->country;
echo $details->city;
로 나라와 도시 정보를 받고 있습니다.

이런 식으로 asn이라는 오브젝트?에 있는 name 의 값을 받으려면 어떻게 해야하나요?
|
답변 4개 / 댓글 5개
2년 전
json_decode() 하기전 문자열이 어떻게 되나요?
답변에 대한 댓글 1개
2년 전
2년 전
테스트 해 봤는데 저렇게 절대로 되지 않습니다.
curl을 사용해 보세요...
잘 됩니다..
답변에 대한 댓글 1개
2년 전
이렇게 해보는건 어떠실까요?
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
echo $details->country; // 국가 정보 출력
echo $details->city; // 도시 정보 출력
echo $details->asn->name; // asn의 name 값 출력
답변에 대한 댓글 1개
shine1204s
2년 전
Warning: Undefined property: stdClass::$asn in
Warning: Attempt to read property "name" on null in
라는 에러가 뜹니다..
Warning: Attempt to read property "name" on null in
라는 에러가 뜹니다..
$details->asn->name;
이렇게는 안되나여?
안되면 디버깅해보세요.
답변에 대한 댓글 2개
shine1204s
2년 전
Warning: Undefined property: stdClass::$asn in
Warning: Attempt to read property "name" on null in
라는 에러가 뜹니다..
Warning: Attempt to read property "name" on null in
라는 에러가 뜹니다..
답변을 작성하려면 로그인이 필요합니다.
이렇게 해야 하는 거 아닌가요?