JSON을 반환하는 API를 사용하고 있습니다. 여기에 JSON 링크가 있습니다. http://getpincodes.info/api.php?pincode=421305 이것은 위 링크의 oupput json입니다 [{ "pincode": "421305", "city": "Vidyashram", "district": "Thane", "state": "MAHARASHTRA"}] 데이터를 읽는 코드는 다음과 같습니다.
$json = file_get_contents("http://getpincodes.info/aenter code herepi.php?pincode=$zip");
$data=json_decode($json);
$city = $data->city;
echo $city;
enter code here
그렇게하는 동안 오류가 발생 함주의 : 비 객체의 속성을 가져 오려고합니다.
네이 키드 오브젝트 대신 결과 배열을받는 것 같습니다. 그래서
$city = $data->city; // does not work: $data is an array
그러나
$city = $data[0]->city; // should work: $data[0] is an object with a city key
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다