내가 사용하는 주소 확인 API에서 데이터를 가져 오려고하고 있으며 데이터를 가져 오는 데 문제가 있습니다. 나는 주소를 cURLing하고 응답을 얻는 데 아무런 문제가 없지만 응답을 처리하는 PHP에 도움이 필요하다.cURL의 JSON 응답 처리
JSON 구조 :
[
{ "input_index": 0,
"candidate_index": 0,
"addressee": "Apple Inc",
"delivery_line_1": "1 Infinite Loop",
"delivery_line_2": "PO Box 42",
"last_line": "Cupertino CA 95014-2083",
"delivery_point_barcode": "950142083017",
"metadata": {
"latitude":"48.12685",
"longitude":"-39.16847"
},
}
{ "input_index": 1,
"candidate_index": 0,
"addressee": "Google Inc",
"delivery_line_1": "1600 Amphitheater Pkwy",
"delivery_line_2": "",
"last_line": "Mountain View CA 94043-1351",
"delivery_point_barcode": "950142083017",
"metadata": {
"latitude":"48.12685",
"longitude":"-39.16847"
},
}
]
내 코드 :
$response = curl_exec($ch);
curl_close($ch);
$rd = json_decode($response);
echo $rd->metadata[0]->latitude;
그러나 나는 Trying to get property of non-object
의 오류가 발생합니다.
내가 뭘 잘못하고 있니?
편집 :
인 print_r ($의 RD); 저를 제공합니다
Array ([0] => stdClass Object ([input_index] => 0 [candidate_index]
=> 0 [addressee] => Randolph Gray [delivery_line_1] => 8758 Sunset Breeze Dr [last_line] => Reno NV 89506-4136 [delivery_point_barcode]
=> 895064136585 [components] => stdClass Object ([primary_number] => 8758 [street_name] => Sunset Breeze [street_suffix] => Dr [city_name]
=> Reno [state_abbreviation] => NV [zipcode] => 89506 [plus4_code] => 4136 [delivery_point] => 58 [delivery_point_check_digit] => 5) [metadata] => stdClass Object ([record_type] => S [zip_type] => Standard [county_fips] => 32031 [county_name] => Washoe [carrier_route] => C038 [congressional_district] => 02 [rdi] => Residential [elot_sequence] => 0381 [elot_sort] => A [latitude] =>
39.63353 [longitude] => -119.89745 [precision] => Zip9 [time_zone] => Pacific [utc_offset] => -8 [dst] => 1) [analysis] => stdClass Object ([dpv_match_code] => Y [dpv_footnotes] => AABB [dpv_cmra] => N [dpv_vacant] => N [active] => Y)) [1] => stdClass Object ([input_index] => 1 [candidate_index] => 0 [addressee] => Julio Valdez [delivery_line_1] => 7464 Gannon Dr [last_line] => Reno NV 89506-3186 [delivery_point_barcode] => 895063186644 [components] => stdClass Object ([primary_number] => 7464 [street_name] => Gannon [street_suffix] => Dr [city_name] => Reno [state_abbreviation] => NV [zipcode] => 89506 [plus4_code] => 3186 [delivery_point] => 64 [delivery_point_check_digit] => 4) [metadata] => stdClass Object ([record_type] => S [zip_type] => Standard [county_fips] => 32031 [county_name] => Washoe [carrier_route] => C038 [congressional_district] => 02 [rdi] => Residential [elot_sequence] => 0048 [elot_sort] => A [latitude] => 39.62646 [longitude] => -119.89913 [precision] => Zip9 [time_zone] => Pacific [utc_offset] => -8 [dst] => 1) [analysis] => stdClass Object ([dpv_match_code] => Y [dpv_footnotes] => AABB [dpv_cmra] => N [dpv_vacant] => N [active] => Y)) [2] => stdClass Object ([input_index] => 2 [candidate_index] => 0 [addressee] => Nicholas Carone [delivery_line_1] => 8685 Bagpipe Cir [last_line] => Reno NV 89506-4165 [delivery_point_barcode] => 895064165853 [components] => stdClass Object ([primary_number] => 8685 [street_name] => Bagpipe [street_suffix] => Cir [city_name] => Reno [state_abbreviation] => NV [zipcode] => 89506 [plus4_code] => 4165 [delivery_point] => 85 [delivery_point_check_digit] => 3) [metadata] => stdClass Object ([record_type] => S [zip_type] => Standard [county_fips] => 32031 [county_name] => Washoe [carrier_route] => C038 [congressional_district] => 02 [rdi] => Residential [elot_sequence] => 0227 [elot_sort] => A [latitude] =>
39.63367 [longitude] => -119.89965 [precision] => Zip9 [time_zone] => Pacific [utc_offset] => -8 [dst] => 1) [analysis] => stdClass Object ([dpv_match_code] => Y [dpv_footnotes] => AABB [dpv_cmra] => N [dpv_vacant] => N [active] => Y)))
'print_r ($ rd)'당신에게 줄래? – bloodyKnuckles
또한 다음과 같이 접근해야합니다 :'$ rd [0] -> metadata-> latitude;'. 배열의 객체가 있습니다 –
@RahilWazir 잘못된 JSON이 수정되었습니다. 오타 일 수도 있습니다. – JakeGould