package api.jisuapi.miyu;
import java.net.URLEncoder;
import api.util.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Search {
public static final String APPKEY = "your_appkey_here";// 你的appkey
public static final String URL = "https://api.jisuapi.com/miyu/search";
public static final int pagenum = 1;
public static final int pagesize = 1;
public static final String keyword = "公鸡";// utf-8
public static void Get() throws Exception {
String result = null;
String url = URL + "?appkey=" + APPKEY + "&keyword=" + URLEncoder.encode(keyword, "utf-8") + "&pagenum="
+ pagenum + "&pagesize=" + pagesize;
try {
result = HttpUtil.sendGet(url, "utf-8");
JSONObject json = JSONObject.fromObject(result);
if (json.getInt("status") != 0) {
System.out.println(json.getString("msg"));
} else {
JSONObject resultarr = json.optJSONObject("result");
String total = resultarr.getString("total");
String pagenum = resultarr.getString("pagenum");
String pagesize = resultarr.getString("pagesize");
System.out.println(total + " " + pagenum + " " + pagesize);
if (resultarr.opt("list") != null) {
JSONArray list = resultarr.optJSONArray("list");
for (int i = 0; i < list.size(); i++) {
JSONObject obj = (JSONObject) list.opt(i);
String content = obj.getString("content");
String answer = obj.getString("answer");
System.out.println(content + " " + answer);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}