- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在处理需要显示所有 ATM 的应用程序。我正在从 google api 获取数据,但我无法获取所有数据。我想获取 latitude
和 longitude
但是当我获取数据时我只得到一个值。
String url = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=23.308003,81.3275914&radius=5000&type=atm&key=AIzaSyCYZoSkxHC_Exym4YBWvXZXwMyJA7dzEB4";
try {
JSONObject jObject = new JSONObject(request(url));
String jj = jObject.getString("status");
JSONArray data = jObject.getJSONArray("results");
location = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
JSONObject geometry = c.getJSONObject("geometry");
JSONObject locate = geometry.getJSONObject("location");
String lat = locate.getString("lat");
String lng = locate.getString("lng");
Log.e("Data", lat+"--"+lng);
//map.put("LocationID", c.getString("id"));
//map.put("placeId",c.getString("place_id"));
//location.add(map);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
最佳答案
我会建议您学习一些解析教程。稍后你可以使用像 gson 或 jackson 这样的库来解析你的 json。现在很多人都不自己写json解析代码了。
一旦你理解了 json 结构,你应该能够自己解析它。
你的json
"results": [ // array
{ // jsonobject
"geometry": { // geometry jsonobject
"location": { // location jsonobject
// values
"lat": 23.3085793,
"lng": 81.353116
}
},
... // the rest of the json
然后
// this is right
JSONArray data = jObject.getJSONArray("results");
之后
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
JSONObject geometry = c.getJSONObject("geometry");
JSONObject location = geometry.getJSONObject("location");
String lat = location.getString("lat");
String lng = location.getString("lng");
Log.d("Location->"," "+lat+" "+lng);
// now do what you want.
// You probably meant to do
map = new HashMap<String, String>();
map.put("lat",lat);
map.pt("lng",lng);
location.add(map);
}
关于android - 如何从 JSONARRAY 中的 JSONOBJECT 获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44969647/
这个问题在这里已经有了答案: final keyword in method parameters [duplicate] (9 个回答) 关闭 8 年前。 在此示例中,声明 Object fina
我的目标:是通过我的函数更新字段获取选定值并使用函数输出值运行它。 问题:当我从列表中选择值时,它不会触发函数,也不会更新字段。 感谢您的帮助。 HTML 12 14 16 18 20 22 24
我有一本具有这种形式的字典: myDict = {'foo': bar, 'foobar baz': qux} 现在,我想拆分字典键中的空格,使其成为下一个键并获取值(重复)。 myDictRev1
vector a; vector b; int temp_holder; cout > temp_holder) a.push_back(temp_holder); cout > temp_h
Java 的开发过程中免不了与 Date 类型纠缠,准备总结一下项目经常使用的日期相关操作,JDK 版本 1.7,如果能够帮助大家节约那么几分钟起身活动一下,去泡杯咖啡,便是极好的,嘿嘿。当然,我
我正在使用 jquery ui 日期选择器来获取 fromDate 和 toDate 以下是from日期的代码 $("#from_date").datepicker({
我是一名优秀的程序员,十分优秀!