接着上一篇
http://blog.csdn.net/huoer_12/article/details/17381991,继续这个话题。
上篇中的类主要用来获取网页的数据,本篇主要讲如何使用上篇中的类及获取导数据后的处理。
本类需要org.json.jar,该文件可在网上找到,文件不大,官网http://www.json.org/,API说明http://www.json.org/java/index.html,可自己下载源代码编译。
CityJSON.java
package com.eabour.weather;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class CityJSON {
private String path;
public CityJSON(String path){
this.path=path;
}
public void getCityCode(){
File file=new File(path);
if("".equals(file.getAbsolutePath())) return ;
JSONObject newCities=new JSONObject();
CityCode cityutil=new CityCode();
try {
//get Province list
Map<String,String> pro=cityutil.getProvinceList();
Set<String> pro_keys=pro.keySet();
ArrayList<JSONObject> proList=new ArrayList<JSONObject>();
for(String key : pro_keys){
System.out.println(pro.get(key));
//create province JSON
JSONObject proJson=new JSONObject();
//get the city's distracts
Map<String,String> city=cityutil.ge