中国天气网城市代码(JSON)获取实现(二)


接着上一篇

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值