/** * 从json解析,获取Book对象 * * @param jsonStr * @return */ public static LogisticInfo parseLogisticsInfo(String jsonStr) { JSONObject json = null; Log.d("DEBUG", "jsonStr: " + jsonStr); LogisticInfo wuliuInfo = new LogisticInfo(); try { json = new JSONObject(jsonStr); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (json != null) { wuliuInfo.init(json); return wuliuInfo; } else { return null; } }
/** * @param info * @return */ public static Set<String> getLocations( LogisticInfo info, Map<String, Map<String, Set<String>>> dizhi) { Set<String> locations = new LinkedHashSet<String>(); if (info == null) { return locations; } if (info.getTrackInfoList() != null) for (TrackInfo trackInfo : info.getTrackInfoList()) { String context = trackInfo.getContext(); if (StringUtils.isNotBlank(context)) { context = StringUtils.substringBeforeLast(context, "正发往"); context = StringUtils.substringBeforeLast(context, "分拨中心"); String local = ""; for (Map.Entry<String, Map<String, Set<String>>> entry : dizhi.entrySet()) { if (context.contains(entry.getKey()) || context.contains(remove(entry.getKey()))) { local = local + entry.getKey(); for (Map.Entry<String, Set<String>> subEntry : entry.getValue().entrySet()) { if (StringUtils.equals(subEntry.getKey(), "市辖区") || StringUtils.equals(subEntry.getKey(), "县") || StringUtils.equals(subEntry.getKey(), "自治区直辖县级行政区划")) { for (String str : subEntry.getValue()) { if (context.contains(str) || context.contains(remove(str))) { local = local + str; break; } } } else if (context.contains(subEntry.getKey()) || context.contains(remove(subEntry.getKey()))) { local = local + subEntry.getKey(); for (String str : subEntry.getValue()) { if (context.contains(str) || context.contains(remove(str))) { local = local + str; break; } } } } break; } else { for (Map.Entry<String, Set<String>> subEntry : entry.getValue().entrySet()) { if (StringUtils.equals(subEntry.getKey(), "市辖区") || StringUtils.equals(subEntry.getKey(), "县") || StringUtils.equals(subEntry.getKey(), "自治区直辖县级行政区划")) { for (String str : subEntry.getValue()) { if (context.contains(str) || context.contains(remove(str))) { local = local + str; break; } } } else if (context.contains(subEntry.getKey()) || context.contains(remove(subEntry.getKey()))) { local = local + subEntry.getKey(); for (String str : subEntry.getValue()) { if (context.contains(str) || context.contains(remove(str))) { local = local + str; break; } } } } } } locations.add(local); } } return locations; }