예 :
{
"destination_addresses" : [ "Milano, Italia" ],
"origin_addresses" : [ "Padova PD, Italia" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "246 km",
"value" : 246492
},
"duration" : {
"text" : "2 ore 36 min",
"value" : 9388
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
이 경우 거리를 얻고 싶어요 246km 답장 주셔서 감사합니다 .. 모르겠어요 ....
다음 array
과 json_decode
같이 로 변환 할 수 있습니다 .
<?php
$json = json_decode('{
"destination_addresses" : [ "Milano, Italia" ],
"origin_addresses" : [ "Padova PD, Italia" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "246 km",
"value" : 246492
},
"duration" : {
"text" : "2 ore 36 min",
"value" : 9388
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}',true);
var_dump($json);
?>
결과는 다음과 같습니다.
array(4) {
["destination_addresses"]=>
array(1) {
[0]=>
string(14) "Milano, Italia"
}
["origin_addresses"]=>
array(1) {
[0]=>
string(17) "Padova PD, Italia"
}
["rows"]=>
array(1) {
[0]=>
array(1) {
["elements"]=>
array(1) {
[0]=>
array(3) {
["distance"]=>
array(2) {
["text"]=>
string(6) "246 km"
["value"]=>
int(246492)
}
["duration"]=>
array(2) {
["text"]=>
string(12) "2 ore 36 min"
["value"]=>
int(9388)
}
["status"]=>
string(2) "OK"
}
}
}
}
["status"]=>
string(2) "OK"
}
을 (를) 얻으려면 km
나중에이 작업을 수행 할 수 있습니다.
<?php
echo $json['rows']['0']['elements']['0']['distance']['text'];
?>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다