从JSON响应中获取特定值

时间:2016-06-18 14:16:21

标签: php arrays json

我得到了Google Maps Distance Matrix API的回复:

{
   "destination_addresses" : [ "334-350 Hicks St, Brooklyn, NY 11201, USA" ],
   "origin_addresses" : [ "565-569 Vermont St, Brooklyn, NY 11207, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "6.5 mi",
                  "value" : 10410
               },
               "duration" : {
                  "text" : "34 mins",
                  "value" : 2045
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

如何准确获得“6.5英里”的价值?

我尝试了这个但不起作用:

$distance = $response_a['rows'][0]['elements'][0]['distance']['text'];

1 个答案:

答案 0 :(得分:2)

您收到了Google API的JSON字符串。在使用之前对其进行解码。

gcc -zexecstack -g -o Shellcode Shellcode.c