【发布时间】:2014-07-29 18:10:10
【问题描述】:
我想在我的网站上创建 gmap。
我找到了,如何获取坐标。
{
"results" : [
{
// body
"formatted_address" : "Puławska, Piaseczno, Polska",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 52.0979041,
"lng" : 21.0293984
},
"southwest" : {
"lat" : 52.0749265,
"lng" : 21.0145743
}
},
"location" : {
"lat" : 52.0860667,
"lng" : 21.0205308
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 52.0979041,
"lng" : 21.0293984
},
"southwest" : {
"lat" : 52.0749265,
"lng" : 21.0145743
}
}
},
"partial_match" : true,
"types" : [ "route" ]
}
],
"status" : "OK"
}
我想得到:
"location" : {
"lat" : 52.0860667,
"lng" : 21.0205308
},
来自这个 Json。
我决定使用 json-simple
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
我的代码是:
String coordinates = //JSON from google
JSONObject json = (JSONObject)new JSONParser().parse(coordinates);
我可以得到第一个孩子:“结果”
String json2 = json.get("results").toString();
json2 显示正确的“结果”正文
但我无法获得“位置”孩子。
怎么做?
谢谢
【问题讨论】:
标签: java json jsonobject