- //这是之前的一个获取缩略图的代码,希望对你有些参考性。
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import net.sf.json.*;
- public class test2 {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- String url = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html";
- //获取id后面的字符串,也就是"XMjU0MjI2NzY0.html"
- int no = url.indexOf("id_");
- //获取id值,也就是"XMjU0MjI2NzY0"
- String videoId = url.substring(no+3, url.indexOf(".html"));
- //获取视频信息数据的URL对象
- URL myurl = new URL("http://v.youku.com/player/getPlayList/VideoIDS/"+videoId+"/timezone/+08/version/5/source/out?password=&ran=2513&n=3");
-
- //从URL对象中获取输入流
- InputStreamReader isr = new InputStreamReader(myurl.openStream());
- //封装
- BufferedReader br = new BufferedReader(isr);
- //readLine获取文本
- String urls = br.readLine();
- //关闭流
- br.close();
- //获取json对象
- JSONObject json = JSONObject.fromObject(urls);
- //获取json数据(data内)
- JSONArray arr = json.getJSONArray("data");
- //获取logo的值并打印
- System.out.println(JSONObject.fromObject(arr.get(0)).get("logo"));
- }
- }
复制代码 |