首页 > 解决方案 > Google Maps Places API 返回无效 JSON

问题描述

谷歌地图正在返回https://jsonlint.com/标记为无效 JSON 的内容。人们留下的评论中有转义单引号的问题。所以像:

{
  "author_name": "Darrell McClendon",
  "author_url": "https://www.google.com/maps/contrib/105899976805332994558/reviews",
  "language": "en",
  "profile_photo_url": "https://lh4.googleusercontent.com/-XmJwNWWFIfM/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3rfAh9eFXs0wNVHCkZgXEc5k2MwXsg/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg",
  "rating": 4,
  "relative_time_description": "10 months ago",
  "text": "Not hard to get here. From I-10 w, turn right into Central Ave. Turn right onto 12th st, and park by the first gate on right. You check in there, but then drive thru the 2nd gate. Can\'t stay in the truck while unloading",
  "time": 1528824337
}

...是一个问题(参见“文本”值)。在此运行 json_decode 将返回 null。

这通常是一个问题吗?尽管上周都在同一个位置进行了测试,但直到今天早上,我才在处理当前的应用程序时遇到它。我可以确认我已经记录了同一个请求的结果,并且它不包含转义的单引号,这就是它当时解码正常的原因。

标签: phpgoogle-maps-api-3google-places-api

解决方案


推荐阅读