首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

依据url读取数据并解析(json)

2012-08-31 
根据url读取数据并解析(json)/*** @param args* @throws IOException*/ public static void main(String[]

根据url读取数据并解析(json)

/**  * @param args  * @throws IOException   */ public static void main(String[] args) throws IOException {  URL url = new URL("https://www.koobe.com.tw/AssociateAPIs/Data/Quota.aspx?bookid=20ddd93c-d34e-40ce-996f-4cf3dd322d16");  Reader reader = new InputStreamReader(new BufferedInputStream(url.openStream()));            int c;            String str = "[";        while ((c = reader.read()) != -1) {             str += (char)c;            }        str += "]";        reader.close();                   System.out.println(str);        //将字符串转百json数据        JSONArray ja = JSONArray.fromObject(str);        JSONObject o=(JSONObject) ja.get(0);        System.out.println(o.get("KoobeData"));
?

?

[{"KoobeData":{"Quota":3}}]
{"Quota":3}

热点排行
Bad Request.