使用PHP从JSON读取值

编程入门 行业动态 更新时间:2024-10-24 22:20:20
本文介绍了使用PHP从JSON读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是JSON和php的新手.我需要在调用json_decode()之后从以下json中获取 lat 和 lng .但是我不知道如何访问它们.

Im new to JSON and php. I need to grab the lat and lng from the following json after calling json_decode(). But I don't know how to access them.

{ "status": "OK", "results": [ { "types": [ "street_address" ], "formatted_address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", "address_components": [ { "long_name": "1600", "short_name": "1600", "types": [ "street_number" ] }, { "long_name": "Amphitheatre Pkwy", "short_name": "Amphitheatre Pkwy", "types": [ "route" ] }, { "long_name": "Mountain View", "short_name": "Mountain View", "types": [ "locality", "political" ] }, { "long_name": "California", "short_name": "CA", "types": [ "administrative_area_level_1", "political" ] }, { "long_name": "United States", "short_name": "US", "types": [ "country", "political" ] }, { "long_name": "94043", "short_name": "94043", "types": [ "postal_code" ] } ], "geometry": { "location": { "lat": 37.4219720, "lng": -122.0841430 }, "location_type": "ROOFTOP", "viewport": { "southwest": { "lat": 37.4188244, "lng": -122.0872906 }, "northeast": { "lat": 37.4251196, "lng": -122.0809954 } } } } ] }

推荐答案

在PHP中,JSON对象解码为对象,而数组解码为数组:

In PHP, JSON objects decode to objects, and arrays to arrays:

$data->results[0]->geometry->location->lat $data->results[0]->geometry->location->lng

更多推荐

使用PHP从JSON读取值

本文发布于:2023-10-29 08:20:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!