@@ -0,0 +1,2404 @@
+package com.napsterwan.cloudweather.util;%0A%0Aimport com.napsterwan.cloudweather.db.City;%0Aimport com.napsterwan.cloudweather.db.Country;%0Aimport com.napsterwan.cloudweather.db.Province;%0A%0Aimport org.json.JSONArray;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0A/**%0A * Created by Napsterwan on 2017/6/7.%0A */%0A%0Apublic class Uitility %7B%0A    /***%0A     * %E5%A4%84%E7%90%86%E7%9C%81%E4%BB%BD%E4%BF%A1%E6%81%AF%0A     * @param response%0A     * @return%0A     */%0A    public static boolean handleProvinceResponse(String response) %7B%0A        try %7B%0A            JSONArray array = new JSONArray(response);%0A            for (int i = 0; i %3C array.length(); i++) %7B%0A                JSONObject jsonObject = array.getJSONObject(i);%0A                Province province = new Province();%0A                province.setProvinceCode(jsonObject.getInt(%22id%22));%0A                province.setName(jsonObject.getString(%22name%22));%0A                province.save();%0A            %7D%0A            return true;%0A        %7D catch (JSONException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return false;%0A    %7D%0A%0A    /**%0A     * %E5%A4%84%E7%90%86%E5%9F%8E%E5%B8%82%E4%BF%A1%E6%81%AF%0A     */%0A    public static boolean handleCityResponse(String response, int provinceId) %7B%0A        try %7B%0A            JSONArray array = new JSONArray(response);%0A            for (int i = 0; i %3C array.length(); i++) %7B%0A                JSONObject jsonObject = array.getJSONObject(i);%0A                City city = new City();%0A                city.setName(jsonObject.getString(%22name%22));%0A                city.setCityCode(jsonObject.getInt(%22id%22));%0A                city.setProvinceId(provinceId);%0A                city.save();%0A            %7D%0A            return true;%0A        %7D catch (JSONException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return false;%0A    %7D%0A%0A    /**%0A     * %E5%A4%84%E7%90%86%E5%8C%BA%E5%8E%BF%E4%BF%A1%E6%81%AF%0A     */%0A    public static boolean handleCountryResponse(String response, int cityId) %7B%0A        try %7B%0A            JSONArray array = new JSONArray(response);%0A            for (int i = 0; i %3C array.length(); i++) %7B%0A                JSONObject object = array.getJSONObject(i);%0A                Country country = new Country();%0A                country.setName(object.getString(%22name%22));%0A                country.setCityId(cityId);%0A                country.setWeatherId(object.getString(%22weather_id%22));%0A                country.save();%0A            %7D%0A            return true;%0A        %7D catch (JSONException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return false;%0A    %7D%0A%7D%0A

添加省，市，区县信息处理工具类