【发布时间】:2011-05-09 17:56:59
【问题描述】:
我是新手程序员,所以请随意评论一些没有意义的东西,以便我可以学习。
我正在开发一个咖啡店查找器 Android 应用程序,该应用程序调用 SimpleGeo API 以获取每个感兴趣的地方。我很难想出一种方法来以我可以用于我的目的的方式存储返回的 JSON 数据。我需要对数据做两件事:首先,我需要一个地图覆盖类来访问它,这样我就可以为每个咖啡店绘制标记(我可以接受);其次,我需要在列表视图中显示数据。
API 调用:
/** Queries SimpleGeo with current location **/
private void getJSONData() {
SimpleGeoPlacesClient client = SimpleGeoPlacesClient.getInstance();
client.getHttpClient().setToken(oauth_key, oauth_secret);
double radius = 25;
try {
client.search(lat, lng, "coffee", null, radius,
new FeatureCollectionCallback() {
public void onSuccess(FeatureCollection collection) {
try {
features = collection.toJSON();
} catch (JSONException e) {
System.out.println(e.getMessage());
}
}
public void onError(String errorMessage) {
System.out.println(errorMessage);
}
});
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
解析数据:
private void parseJSONData() throws JSONException {
for (int i = 0; i < features.length(); i++) {
JSONObject feature = features.getJSONObject(i).getJSONObject(
"feature");
}
}
我目前正在尝试使用this 教程中概述的 GSON 从数据中创建 java 对象。 SQLite 适合这个吗?任何专业提示将不胜感激。
谢谢。
【问题讨论】:
标签: java android json parsing gson