求助一个php获取json数据的问题

[复制链接]
查看11 | 回复1 | 2011-11-1 01:24:02 | 显示全部楼层 |阅读模式
要求用php语言分别得到Point坐标值:$lat=\'-122.0828900\';$lng=\'37.4220827\';json数据如下,{\"name\":\"1600AmphitheatreParkway,MountainView,CA\",\"Status\":{\"code\":200,\"request\":\"geocode\"},\"Placemark\":[{\"id\":\"p1\",\"address\":\"1600AmphitheatrePkwy,芒廷维尤,加利福尼亚州94043,美国\",\"AddressDetails\":{\"Accuracy\":8,\"Country\":{\"AdministrativeArea\":{\"AdministrativeAreaName\":\"CA\",\"Locality\":{\"LocalityName\":\"MountainView\",\"PostalCode\":{\"PostalCodeNumber\":\"94043\"},\"Thoroughfare\":{\"ThoroughfareName\":\"1600AmphitheatrePkwy\"}}},\"CountryName\":\"USA\",\"CountryNameCode\":\"US\"}},\"ExtendedData\":{\"LatLonBox\":{\"north\":37.4234317,\"south\":37.4207337,\"east\":-122.0815410,\"west\":-122.0842390}},\"Point\":{\"coordinates\":[-122.0828900,37.4220827,0]}}]}
回复

使用道具 举报

千问 | 2011-11-1 01:24:02 | 显示全部楼层
$json=\'原数据\';$d=json_decode($json,true);echo\'lat:\'.$d[\'Placemark\'][0][\'Point\'][\"coordinates\"][0].\'br/\';echo\'lng:\'.$d[\'Placemark\'][0][\'Point\'][\"coordinates\"][1].\'br/\';=========================lat:-122.08289lng:37.4220827============代码有一个前提:php文件和json数据必须是utf8编码。不能为gbk或ascii码因为json数据中包含中文,而javascript和json都是以utf8为标准字符编码。PHP的json_decode也只支持UTF-8编码。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行