Copyright notice: This is the original article of the blogger. It can't be reproduced without the permission of the blogger. https://blog.csdn.net/u010741376/article/details/45055657
Abstract is obtained by calling the abstract list API:
After calling, it will return the list of collected abstracts, including four kinds of classified articles: prose, wonderful flower, history and economy
Address: http://api.1-blog.com/biz/bizserver/article/list.do
Request parameter: page: paging, page number, default is 1, size: paging size, default is 10; type: the article type to get, not all classifications
Return result:
{ "status": "000000", --- return status, six zeros indicate success "desc": null, ---- return result description, six zeros indicate success "detail": [--- specific article list, an array { "Title": "Qing Dynasty commerce", --- article title "Article" URL ":" http: / / XXXX ", --- article address "My" abstract ":" XXX ", --- joke summary "Article" type ":" 2 ", --- article type, 0: Prose 1: wonderful work 2: economy 3: Wild history }, { "Title": "Sun Yat Sen: Thinking of a true patriot", --- title of the article "Article" URL ":" http: / / XXXX ", --- article address "My" abstract ":" XXX ", --- joke summary "Article" type ":" 3 ", --- article type, 0: Prose 1: wonderful work 2: economy 3: Wild history } ] }
Entity class:
package com.web.entity; import java.util.List; /** * Abstract entity class * @author Administrator * */ public class Essay { private String status; private String desc; private List<SaySon> detail; public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } public List<SaySon> getDetail() { return detail; } public void setDetail(List<SaySon> detail) { this.detail = detail; } }
package com.web.entity; public class SaySon { private String title; private String article_url; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getArticle_url() { return article_url; } public void setArticle_url(String articleUrl) { article_url = articleUrl; } public String getMy_abstract() { return my_abstract; } public void setMy_abstract(String myAbstract) { my_abstract = myAbstract; } public String getArticle_type() { return article_type; } public void setArticle_type(String articleType) { article_type = articleType; } private String my_abstract; private String article_type; }
Core categories:
The results show that:package com.web.util; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import com.google.gson.Gson; import com.web.entity.Essay; import com.web.entity.SaySon; /** * Get Abstract tool class * @author Administrator * */ public class AbstractUtil { /** * Send http request to get return result */ public static String httpRequest(String requestUrl){ StringBuffer sb=new StringBuffer(); try { URL url=new URL(requestUrl); HttpURLConnection httpUrlConn=(HttpURLConnection)url.openConnection(); httpUrlConn.setDoInput(true); httpUrlConn.setUseCaches(false); httpUrlConn.setRequestMethod("GET"); httpUrlConn.connect(); /** * Converts the returned input stream to a string */ InputStream inputStream=httpUrlConn.getInputStream(); InputStreamReader inputStreamReader=new InputStreamReader(inputStream,"utf-8"); BufferedReader reader=new BufferedReader(inputStreamReader); String line=null; while((line=reader.readLine())!=null){ sb.append(line); } /** * Release resources */ reader.close(); inputStreamReader.close(); inputStream.close(); inputStream=null; httpUrlConn.disconnect(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return sb.toString(); } /** * Get abstract content */ public static List<SaySon> getAbstract(){ String requestUrl="http://api.1-blog.com/biz/bizserver/article/list.do?size=5&page=1"; String json=httpRequest(requestUrl); Gson gson=new Gson(); Essay essay=gson.fromJson(json,Essay.class); return essay.getDetail(); } public static void main(String[] args) { List<SaySon> s=getAbstract(); for(SaySon say:s){ System.out.println(say.getTitle()+"-"+say.getArticle_type()+"-"+say.getArticle_url()+"-"+say.getMy_abstract()); } } }