json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例
json-lib-2.4-jdk15.jar所需全部JAR包.rar 点击即可免费下载。
开彩网api的免费接口 http://f.apiplus.net/ssq.json,免费的开奖数据延迟3-6分钟,两次请求不能少于3秒,可以请求最近开奖1-20期的数据,这个对双色球来说足够了
{"rows":1,"code":"ssq","info":"免费接口随机延迟3-6分钟,实时接口请访问opencai.net","data":[{"expect":"2017090","opencode":"01,07,10,16,22,33+09","opentime":"2017-08-03 21:18:20","opentimestamp":1501766300}]}
public static Map<String, Object> getLastSsqDataByApiplus() { Map<String, Object> maps = new HashMap<String, Object>(); //http://f.apiplus.net/ssq-1.json,http://f.apiplus.net/ssq-20.json 最多只能取到1-20期,默认5期 String body = getApiJson("http://f.apiplus.net/ssq-1.json"); if ("".equals(body)) { log.info("body="); return maps; } try { // 解析内容 JSONObject obj = JSONObject.fromObject(body); // int rows = obj.getInt("rows"); JSONArray data = obj.getJSONArray("data"); for(int i =0; i<data.size(); i++){ JSONObject dt = data.getJSONObject(i); String opencode = dt.getString("opencode"); String reds = opencode.split("\\+")[0]; String openblue = opencode.split("\\+")[1]; String opennumber = dt.getString("expect"); // System.out.println("opennumber:" +opennumber); // System.out.println("opencode:" + opencode); // System.out.println("openreds:" + openreds); // System.out.println("openblue:" + openblue); List<Integer> openreds = new ArrayList<Integer>(); for(int j=0; j<6; j++){ openreds.add(Integer.parseInt(reds.split(",")[j])); } maps.put("openreds", openreds); maps.put("opennumber", Integer.parseInt(opennumber)); maps.put("openblue", Integer.parseInt(openblue)); } } catch (Exception e) { e.printStackTrace(); } return maps; }