디코딩하려고하는 일부 JSON이 있습니다. 올바르게 값을 추출하지만 오류가 발생합니다. 여기 또 다른 간단한 PHP JSON 디코드 챌린지
는var_dump
이다
["success"]=>
bool(true)
["providers"]=>
array(2) {
[0]=>
object(stdClass)#5 (15) {
["address1"]=>
string(14) "3240 W Lake St"
["address2"]=>
NULL
["city"]=>
string(11) "Minneapolis"
["crossStreet"]=>
string(26) "Lake Street & Market Plaza"
["description"]=>
string(55) "test location28402 description of services/prices/hours"
["distance"]=>
float(0.42900015862223)
["lat"]=>
float(44.948469)
["lon"]=>
float(-93.321155)
["name"]=>
string(17) "testlocation28402"
["phone"]=>
string(10) "6125551212"
["precise"]=>
bool(true)
["state"]=>
string(2) "MN"
["url"]=>
string(41) "http://www.testlocation28402.com?id=28402"
["urlCaption"]=>
string(25) "www.testlocation28402.com"
["zip"]=>
string(9) "554164512"
}
[1]=>
object(stdClass)#6 (15) {
["address1"]=>
string(19) "4335 Excelsior Blvd"
["address2"]=>
NULL
["city"]=>
string(16) "Saint Louis Park"
["crossStreet"]=>
NULL
["description"]=>
string(55) "test location26358 description of services/prices/hours"
["distance"]=>
float(0.91979730006713)
["lat"]=>
float(44.935773)
["lon"]=>
float(-93.33489)
["name"]=>
string(17) "testlocation26358"
["phone"]=>
string(10) "6125551212"
["precise"]=>
bool(true)
["state"]=>
string(2) "MN"
["url"]=>
string(41) "http://www.testlocation26358.com?id=26358"
["urlCaption"]=>
string(25) "www.testlocation26358.com"
["zip"]=>
string(9) "554164811"
}
}
["errors"]=>array(0) {
}
}
위 변수 $jso
N의 var_dump
이다.
$json = json_decode($surescript);
foreach ($json as $providers){
foreach($providers as $onespot) {
echo "*";
echo $onespot->city;
echo "\n";
}
}
이 출력 :
경고 : /홈/내용의 foreach는()에 대한 공급 잘못된 인수/7백97만3천1백96분의 96/HTML/I는 함께 CITY 필드를 추출하는 것을 시도하고있다 라인 채널/MIL432/storeFinder_2.php153
* 미니애폴리스 * 세인트 루이스 공원
그래서, 올바른 중첩 된 변수를 얻고 있지만 두 번째 foreach 루프에서 오류가 발생합니다.
내가 뭘 잘못하고 있니?
미리 도움을 주셔서 감사합니다.