Package API;
Import Java.util.Vector;
Import Javax.swing.JOptionPane;
Import Net.sf.json.JSONArray;
Import Net.sf.json.JSONObject; /** * @TODO Get book information * @author love to knock the code of the Sea * @return Book basic information collection * * public class Getbookinfo {public static vector<string& Gt
GETBYISBN (String ISBN) {vector<string> book=null;
String Publish,name,author,price;
try {book=new vector<string> ();
String result=httputil.sendget ("https://api.douban.com/v2/book/isbn/:" +ISBN, "Utf-8");
Converts the return string to a JSON object Jsonobject json=jsonobject.fromobject (result);
Get Publishing house Publish=json.get ("publisher"). ToString ();
Get the title Name=json.get ("title"). ToString ();
Get the author, because the obtained is an array, so to convert Jsonarray arrauthor=jsonarray.fromobject (json.get ("author"));
Author=arrauthor.getstring (0). toString ();
Get Prices Price=json.get ("price"). ToString ();
Store the resulting information in the collection Book.add (Name);
Book.add (Author);
Book.add (price);
Book.add (Publish); catch (Exception e) {Joptionpane.showmessagEdialog (NULL, "Network connection failure ...");
return book;
}
}
The main is the use of Watercress API interface:
Https://developers.douban.com/wiki/?title=book_v2