读书人

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

发布时间: 2012-08-31 12:55:03 作者: rapoo

根据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}

读书人网 >JavaScript

热点推荐