route是一个Map<*,*>,需要解析data中的id
解析如下:
if (null != route) {
Map<?, ?> routeData = (Map<?, ?>) route.get("data");
if (routeData != null) {
JSONObject jsonObject = GsonUtil.toJSONObject(routeData);
Object host_id = jsonObject.optInt("host_id");
}
}
GsonUtil是cn.colorv.net.retrofit包下的
/**
* map to JSONObject
* @param map
* @return
*/
public static JSONObject toJSONObject(Map map) {
Gson gson = new Gson();
try {
return new JSONObject(gson.toJson(map));
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
Gson是com.google.gson.Gson谷歌的Gson
感悟:GsonUtil中还是有不少好用的工具类的,不错