String longurl = “”; //输入长链接地址
BufferedReader reader = null;
try {
longurl = URLEncoder.encode(longurl, “GBK”);
URL url = new URL(“http://api.t.sina.com.cn/short_url/shorten.json?source=2546260130&url_long=” + longurl);
InputStream iStream = url.openStream();
reader = new BufferedReader(new InputStreamReader(iStream));
String jsonStr = reader.readLine();
JSONObject jsonObj = JSONObject.parseArray(jsonStr).getJSONObject(0);
System.out.println(jsonObj.getString(“url_short”));
} catch (Exception e) {
} finally {
IOUtils.closeQuietly(reader);
}