1、public String queryThreeOpenArea() /* 从数据库中拿到的数据 */List areaCityList = queryArea(1);/* 把数据封装到mProvince. 去 */List mProvinceItemList = new ArrayList();/* 封装的过程 */* 1、保存所有的省 */ mSmAreaCity.getAreaId();/区域id/ mSmAreaCity.getCountyName();/区域名称/ mSmAreaCity.getCityName();/城市名称/ mSmAreaCity.getAreaProv();/
2、省名称Set shengMap = new HashSet();/ 保存所有的省的名称集合Map shiMap = new HashMap();Map quMap = new HashMap();Map idMap = new HashMap();/每个id,对应的区域名称for (SmAreaCity mSmAreaCity : areaCityList) / 遍历所有的地区名称,包括id/* 1、保存所有的省的名称 */shengMap.add(mSmAreaCity.getAreaProv();/* 2、根据省名称保存所有的城市名称 */if (shiMap.get(mSmAreaCit
3、y.getAreaProv() = null) shiMap.put(mSmAreaCity.getAreaProv(), new ArrayList();ArrayList mList = (ArrayList) shiMap.get(mSmAreaCity.getAreaProv();if (mList.indexOf(mSmAreaCity.getCityName() = -1) / 查询当前省里面是否保存过城市/* 曾经没保存过 */mList.add(mSmAreaCity.getCityName();/* 3、根据城市,保存所有的区域 */if (quMap.get(mSmArea
4、City.getCityName() = null) quMap.put(mSmAreaCity.getCityName(), new ArrayList();ArrayList mListQu = (ArrayList) quMap.get(mSmAreaCity.getCityName();if (mListQu.indexOf(mSmAreaCity.getAreaId() = -1) mListQu.add(“ + mSmAreaCity.getAreaId();/*4、每个区域对应的id*/idMap.put(“+mSmAreaCity.getAreaId(), mSmAreaCit
5、y.getCountyName();/* 打印测试 */System.out.println(“-shengMap“+shengMap);System.out.println(“-shiMap“+shiMap);System.out.println(“-quMap“+quMap);/* 开始封装数据 ,省 */for (String mSheng : shengMap) ProvinceItem mProvinceItem = new ProvinceItem();mProvinceItem.setProvince_name(mSheng);/ 省的属性1ArrayList mCityList
6、 = new ArrayList();/* 城市 */List mList_1 = shiMap.get(mSheng);for (int i = 0; i mDistrictItem = new ArrayList();List mList_2 = quMap.get(mList_1.get(i);for (int j = 0; j “+mProvinceItemList);String obj = null;try obj = jsonMapper.writeValueAsString(mProvinceItemList); catch (JsonProcessingException e) / TODO Auto-generated catch blocke.printStackTrace();return obj;