Java Code Examples for cn.hutool.json.JSONObject#put()
The following examples show how to use
cn.hutool.json.JSONObject#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockFilterHandler.java From v-mock with MIT License | 6 votes |
/** * 包装请求参数为json * * @param request 请求 * @return requestJson */ @SneakyThrows private String requestToJson(HttpServletRequest request) { JSONObject requestJsonObj = new JSONObject(); // get all header Map<String, String> headerMap = ServletUtil.getHeaderMap(request); requestJsonObj.put("headers", headerMap); // get all param Map<String, String> paramMap = ServletUtil.getParamMap(request); requestJsonObj.put("params", paramMap); // body @Cleanup BufferedReader reader = request.getReader(); String body = reader.lines().collect(Collectors.joining(System.lineSeparator())); requestJsonObj.put("body", body); return requestJsonObj.toString(); }
Example 2
Source File: ApiController.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 查询字幕 */ public void zimu_list() { HttpRequest request = getRequest(); HttpResponse response = getResponse(); String data = request.getParaToStr("data"); if(data == null) { outJsonpMessage(request,response, 1, "请求数据错误"); return; } JSONObject dataJson = JSONUtil.parseObj(data); SearchParm searchParm = new SearchParm(); searchParm.from_sheshou = dataJson.getJSONObject("searchParm").getBool("from_sheshou"); searchParm.from_subhd = dataJson.getJSONObject("searchParm").getBool("from_subhd"); searchParm.from_xunlei = dataJson.getJSONObject("searchParm").getBool("from_xunlei"); searchParm.from_zimuku = dataJson.getJSONObject("searchParm").getBool("from_zimuku"); try { DownZIMu.searchList(searchParm); System.out.println(DownZIMu.dataArr); }catch(Exception e) { logger.error(e); outJsonpMessage(request,response, 1, "查询出错"); return; } JSONObject resp = new JSONObject(); resp.put("list", DownZIMu.dataArr); outJsonpMessage(request,response, 0, "OK", resp); }
Example 3
Source File: Base.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
protected JSONObject getAjaxMessage(int result, String message, JSONObject data) { JSONObject json = new JSONObject(); json.put("result", result); json.put("message", message); if (data != null) { json.putAll(data); } return json; }
Example 4
Source File: ExtractApiController.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载压缩文件中的字幕 * @param data * @return */ public void down_archive_file() { HttpRequest request = getRequest(); HttpResponse response = getResponse(); String data = request.getParaToStr("data"); if(data == null) { outJsonpMessage(request,response, 1, "请求数据错误"); return; } logger.info("data="+data); if(data == null || data.length() < 10) { logger.error("data=null"); outJsonpMessage(request,response, 1, "参数错误"); return; } JSONObject dataJson = JSONUtil.parseObj(data); JSONArray items = dataJson.getJSONArray("items"); if(items == null || items.size() == 0) { logger.error("items=null"); outJsonpMessage(request,response, 1, "参数错误"); return; } JSONObject resp = new JSONObject(); resp.put("saveSelected", ExtractDialog.extractDialog.saveSelected(items)); outJsonpMessage(request,response, 0, "OK", resp); }
Example 5
Source File: ExtractApiController.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取初始化数据 */ public void get_init_data() { JSONObject resp = new JSONObject(); JSONArray list = new JSONArray(); for (int i = 0; i < ExtractDialog.extractDialog.archiveFiles.size(); i++) { File file = ExtractDialog.extractDialog.archiveFiles.get(i); String title = file.getName(); if(!ArrayUtil.contains(AppConfig.subExtNames, StringUtil.extName(file).toLowerCase())){ continue; } String key = title; JSONObject row = new JSONObject(); row.put("key", key); row.put("title", title); row.put("size", file.length()); row.put("sizeF", StringUtil.getPrintSize(file.length())); list.add(row); } resp.put("list", list); resp.put("title", ExtractDialog.extractDialog.title); resp.put("archiveExt", ExtractDialog.extractDialog.archiveExt); resp.put("archiveSize", ExtractDialog.extractDialog.archiveData.length); resp.put("archiveSizeF", StringUtil.getPrintSize(ExtractDialog.extractDialog.archiveData.length)); outJsonpMessage(request,response, 0, "OK", resp); }
Example 6
Source File: SubHDCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载字幕 * @param url * @return */ public static JSONObject downContent(String url) { String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url); Document doc = Jsoup.parse(result); Elements matchList = doc.select("#down"); if(matchList.size() == 0)return null; Element down = matchList.get(0); Map<String, Object> postData = new HashMap<String, Object>(); postData.put("sub_id", matchList.attr("sid")); postData.put("dtoken", down.attr("dtoken")); result = HtHttpUtil.http.post(baseUrl+"/ajax/down_ajax", postData); if(result == null || !result.contains("}"))return null; JSONObject resultJson = JSONUtil.parseObj(result); if(resultJson == null || !resultJson.getBool("success"))return null; String downUrl = resultJson.getStr("url"); String filename = StringUtil.basename(downUrl); //HtHttpUtil.http.debug=true; byte[] data = HtHttpUtil.http.getBytes(downUrl, HtHttpUtil.http._ua, baseUrl+url); JSONObject resp = new JSONObject(); resp.put("filename", filename); resp.put("ext", StringUtil.extName(filename).toLowerCase()); resp.put("data", Base64.encode(data)); return resp; }
Example 7
Source File: DownZIMu.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
public static void addRow(String key, String title, String rate, JSONObject data, String from) { JSONObject dataRow = new JSONObject(); dataRow.put("key", key); dataRow.put("title", title); dataRow.put("rate", rate); dataRow.put("data", data); dataRow.put("from", from); dataArr.add(dataRow); }
Example 8
Source File: SecurityToolsTest.java From teaching with Apache License 2.0 | 5 votes |
@Test public void Test(){ MyKeyPair mkeyPair = SecurityTools.generateKeyPair(); JSONObject msg = new JSONObject(); msg.put("name", "党政辉"); msg.put("age", 50); JSONObject identity = new JSONObject(); identity.put("type", "01"); identity.put("no", "210882165896524512"); msg.put("identity", identity); // 签名加密部分 SecuritySignReq signReq = new SecuritySignReq(); // data为要加密的报文字符串 signReq.setData(msg.toString()); // 为rsa私钥 signReq.setPrikey(mkeyPair.getPriKey()); // 调用签名方法 SecuritySignResp sign = SecurityTools.sign(signReq); // 打印出来加密数据 // signData为签名数据 // data为aes加密数据 // asekey为ras加密过的aeskey System.out.println(new JSONObject(sign).toStringPretty()); // 验签解密部分 SecurityReq req = new SecurityReq(); //对方传过来的数据一一对应 req.setAesKey(sign.getAesKey()); req.setData(sign.getData()); req.setSignData(sign.getSignData()); //我们的公钥 req.setPubKey(mkeyPair.getPubKey()); //验签方法调用 SecurityResp securityResp = SecurityTools.valid(req); //解密报文data为解密报文 //sucess 为验签成功失败标志 true代码验签成功,false代表失败 System.out.println(new JSONObject(securityResp).toStringPretty()); }
Example 9
Source File: ZIMuKuCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载字幕 * @param url * @return */ public static JSONObject downContent(String url) { String result = httpGet(baseUrl+url); String downUrl = RegexUtil.getMatchStr(result, "<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\"" , Pattern.DOTALL); if(downUrl == null)return null; if(!downUrl.startsWith("http")) { downUrl = baseUrl + downUrl; } result = httpGet(downUrl); if(result == null)return null; //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL); if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null; //HtHttpUtil.http.debug=true; HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl); int i = 0; while(httpResp == null && resList.size() > ++i) { httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl); } //System.out.println(httpResp); if(httpResp == null)return null; String filename = HtHttpUtil.getFileName(httpResp); byte[] data = httpResp.bodyBytes(); //System.out.println(filename); JSONObject resp = new JSONObject(); resp.put("filename", filename); resp.put("ext", StringUtil.extName(filename).toLowerCase()); resp.put("data", Base64.encode(data)); return resp; }
Example 10
Source File: SecurityToolsTest.java From jeecg-boot with Apache License 2.0 | 5 votes |
@Test public void Test(){ MyKeyPair mkeyPair = SecurityTools.generateKeyPair(); JSONObject msg = new JSONObject(); msg.put("name", "党政辉"); msg.put("age", 50); JSONObject identity = new JSONObject(); identity.put("type", "01"); identity.put("no", "210882165896524512"); msg.put("identity", identity); // 签名加密部分 SecuritySignReq signReq = new SecuritySignReq(); // data为要加密的报文字符串 signReq.setData(msg.toString()); // 为rsa私钥 signReq.setPrikey(mkeyPair.getPriKey()); // 调用签名方法 SecuritySignResp sign = SecurityTools.sign(signReq); // 打印出来加密数据 // signData为签名数据 // data为aes加密数据 // asekey为ras加密过的aeskey System.out.println(new JSONObject(sign).toStringPretty()); // 验签解密部分 SecurityReq req = new SecurityReq(); //对方传过来的数据一一对应 req.setAesKey(sign.getAesKey()); req.setData(sign.getData()); req.setSignData(sign.getSignData()); //我们的公钥 req.setPubKey(mkeyPair.getPubKey()); //验签方法调用 SecurityResp securityResp = SecurityTools.valid(req); //解密报文data为解密报文 //sucess 为验签成功失败标志 true代码验签成功,false代表失败 System.out.println(new JSONObject(securityResp).toStringPretty()); }
Example 11
Source File: MainWinJsApp.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取初始化数据 */ public String getInitData() { JSONObject resp = new JSONObject(); JSONObject fileinfo = new JSONObject(); fileinfo.put("lastSelPath", MovFileInfo.lastSelPath); fileinfo.put("movFilename", MovFileInfo.movFilename); resp.put("fileinfo", fileinfo); resp.put("searchParm", JSONUtil.parseObj(SearchParm.def)); resp.put("serverPort", AppConfig.serverPort); return resp.toString(); }
Example 12
Source File: ZIMuKuCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载字幕 * @param url * @return */ public static JSONObject downContent(String url) { String result = httpGet(baseUrl+url); String downUrl = RegexUtil.getMatchStr(result, "<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\"" , Pattern.DOTALL); if(downUrl == null)return null; if(!downUrl.startsWith("http")) { downUrl = baseUrl + downUrl; } result = httpGet(downUrl); if(result == null)return null; //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL); if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null; //HtHttpUtil.http.debug=true; HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl); int i = 0; while(httpResp == null && resList.size() > ++i) { httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl); } //System.out.println(httpResp); if(httpResp == null)return null; String filename = HtHttpUtil.getFileName(httpResp); byte[] data = httpResp.bodyBytes(); //System.out.println(filename); JSONObject resp = new JSONObject(); resp.put("filename", filename); resp.put("ext", StringUtil.extName(filename).toLowerCase()); resp.put("data", Base64.encode(data)); return resp; }
Example 13
Source File: ZIMuKuCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取下载网址列表 * @return */ public static JSONArray getDetailList(String url) { String result = httpGet(baseUrl+url); //System.out.println(result); Document doc = Jsoup.parse(result); Elements matchList = doc.select("#subtb tbody tr"); if(matchList.size() == 0)return new JSONArray(); //System.out.println(matchList.html()); JSONArray resList = new JSONArray(); for(int i = 0 ; i < matchList.size(); i++) { Element row = matchList.get(i); JSONObject resRow = new JSONObject(); resRow.put("url", row.selectFirst("a").attr("href")); resRow.put("title", row.selectFirst("a").attr("title")); resRow.put("ext", row.selectFirst(".label-info").text()); Elements authorInfos = row.select(".gray"); StringBuffer authorInfo = new StringBuffer(); authorInfos.forEach(element ->{ authorInfo.append(element.text() + ","); }); if(authorInfo.length() > 0) { resRow.put("authorInfo", authorInfo.toString().substring(0, authorInfo.length()-1)); }else { resRow.put("authorInfo", ""); } resRow.put("lang", row.selectFirst("img").attr("alt")); resRow.put("rate", row.selectFirst(".rating-star").attr("title").replace("字幕质量:", "")); resRow.put("downCount", row.select("td").get(3).text()); resList.add(resRow); } return resList; }
Example 14
Source File: Base.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
protected JSONObject getAjaxMessage(int result, String message, JSONObject data) { JSONObject json = new JSONObject(); json.put("result", result); json.put("message", message); if (data != null) { json.putAll(data); } return json; }
Example 15
Source File: ExtractApiController.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 下载压缩文件中的字幕 * @param data * @return */ public void down_archive_file() { HttpRequest request = getRequest(); HttpResponse response = getResponse(); String data = request.getParaToStr("data"); if(data == null) { outJsonpMessage(request,response, 1, "请求数据错误"); return; } logger.info("data="+data); if(data == null || data.length() < 10) { logger.error("data=null"); outJsonpMessage(request,response, 1, "参数错误"); return; } JSONObject dataJson = JSONUtil.parseObj(data); JSONArray items = dataJson.getJSONArray("items"); if(items == null || items.size() == 0) { logger.error("items=null"); outJsonpMessage(request,response, 1, "参数错误"); return; } JSONObject resp = new JSONObject(); resp.put("saveSelected", ExtractDialog.extractDialog.saveSelected(items)); outJsonpMessage(request,response, 0, "OK", resp); }
Example 16
Source File: ExtractApiController.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取初始化数据 */ public void get_init_data() { JSONObject resp = new JSONObject(); JSONArray list = new JSONArray(); for (int i = 0; i < ExtractDialog.extractDialog.archiveFiles.size(); i++) { File file = ExtractDialog.extractDialog.archiveFiles.get(i); String title = file.getName(); if(!ArrayUtil.contains(AppConfig.subExtNames, StringUtil.extName(file).toLowerCase())){ continue; } String key = title; JSONObject row = new JSONObject(); row.put("key", key); row.put("title", title); row.put("size", file.length()); row.put("sizeF", StringUtil.getPrintSize(file.length())); list.add(row); } resp.put("list", list); resp.put("title", ExtractDialog.extractDialog.title); resp.put("archiveExt", ExtractDialog.extractDialog.archiveExt); resp.put("archiveSize", ExtractDialog.extractDialog.archiveData.length); resp.put("archiveSizeF", StringUtil.getPrintSize(ExtractDialog.extractDialog.archiveData.length)); outJsonpMessage(request,response, 0, "OK", resp); }
Example 17
Source File: DownZIMu.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
public static void addRow(String key, String title, String rate, JSONObject data, String from) { JSONObject dataRow = new JSONObject(); dataRow.put("key", key); dataRow.put("title", title); dataRow.put("rate", rate); dataRow.put("data", data); dataRow.put("from", from); dataArr.add(dataRow); }
Example 18
Source File: MockFilterHandler.java From v-mock with MIT License | 4 votes |
/** * 成功场合 * * @param mockResponse * @param response */ private void successAndLog(MockUrl mockUrl, MockResponse mockResponse, HttpServletRequest request, HttpServletResponse response) { // 日志处理,只有成功命中的场合才记录详细,防止产生过多垃圾数据。 JSONObject responseDetailJson = new JSONObject(); MockLog mockLog = new MockLog(); // 命中url,系统中配置的,可能是带path占位符的 mockLog.setHitUrl(mockUrl.getUrl()); // 实际url mockLog.setRequestUrl(getProcessedUrl(request)); // ip mockLog.setRequestIp(ServletUtil.getClientIP(request)); // request method mockLog.setRequestMethod(request.getMethod()); // request detail mockLog.setRequestDetail(requestToJson(request)); // header逻辑处理 String customHeader = mockResponse.getCustomHeader(); if (StrUtil.isNotBlank(customHeader)) { // 将custom header存储的json 反序列化,并遍历存入header. JSONArray jsonArray = new JSONArray(customHeader); jsonArray.forEach(jsonItem -> { String key = ((JSONObject) jsonItem).getStr("key"); String val = ((JSONObject) jsonItem).getStr("val"); response.addHeader(key, val); }); // header responseDetailJson.put("respHeader", jsonArray); } // 默认返回contentType为json String contentType = response.getContentType(); if (StrUtil.isBlank(contentType)) { response.setContentType(ContentType.JSON.toString(UTF_8)); } // 响应http码 responseDetailJson.put("respStatus", mockResponse.getStatusCode()); response.setStatus(mockResponse.getStatusCode()); // 相应内容 responseDetailJson.put("respContent", mockResponse.getContent()); mockLog.setResponseDetail(responseDetailJson.toString()); // 异步插入 logService.asyncInsert(mockLog); outMsg(mockResponse.getContent(), response); }
Example 19
Source File: SubHDCommon.java From SubTitleSearcher with Apache License 2.0 | 4 votes |
/** * 获取下载网址列表 * @return */ public static JSONArray getDetailList(String url) { String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url); Document doc = Jsoup.parse(result); Elements matchList = doc.select(".d_table tr"); //System.out.println(matchList.html()); JSONArray detailList = new JSONArray(); for (Element matchRow : matchList) { if(matchRow.select(".dt_edition").size() == 0)continue; String html = matchRow.html(); String htmlLower = html.toLowerCase(); String downUrl = matchRow.select(".dt_down a").attr("href"); String title = matchRow.select(".dt_edition a").text().trim(); int downCount = Integer.valueOf(RegexUtil.getMatchStr(matchRow.select(".dt_count").text(), "([\\d]+)")); String ext = ""; for(String extName : AppConfig.subExtNames) { //if(StrUtil.isNotEmpty(RegexUtil.getMatchStr(html, "(>"+extName+"<)", Pattern.CASE_INSENSITIVE))) { if(htmlLower.contains(">"+extName+"<")) { ext += extName; ext += ","; } } if(ext.endsWith(",")) { ext=ext.substring(0, ext.length()-1); }else { ext="其它"; } String lang = ""; String[] langList = new String[] {"双语", "简体", "繁体", "英文"}; for(String langName : langList) { if(htmlLower.contains(">"+langName+"<")) { lang += langName; lang += ","; } } if(lang.endsWith(",")) { lang=lang.substring(0, lang.length()-1); }else { lang="其它"; } Elements labels = matchRow.select(".label"); StringBuffer labelInfo = new StringBuffer(); labels.forEach(element ->{ labelInfo.append(element.text() + ","); }); if(labelInfo.length() > 0) { labelInfo.delete(labelInfo.length()-1, labelInfo.length()); } String zimuzu = matchRow.select("a.gray").text(); JSONObject dataRow = new JSONObject(); dataRow.put("url", downUrl); dataRow.put("title", title); dataRow.put("ext", ext); dataRow.put("lang",lang); dataRow.put("rate", "-"); dataRow.put("downCount", downCount); dataRow.put("labelInfo", labelInfo); dataRow.put("zimuzu", zimuzu); detailList.add(dataRow); } return detailList; }
Example 20
Source File: SubHDCommon.java From SubTitleSearcher with Apache License 2.0 | 4 votes |
/** * 获取下载网址列表 * @return */ public static JSONArray getDetailList(String url) { String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url); Document doc = Jsoup.parse(result); Elements matchList = doc.select(".d_table tr"); //System.out.println(matchList.html()); JSONArray detailList = new JSONArray(); for (Element matchRow : matchList) { if(matchRow.select(".dt_edition").size() == 0)continue; String html = matchRow.html(); String htmlLower = html.toLowerCase(); String downUrl = matchRow.select(".dt_down a").attr("href"); String title = matchRow.select(".dt_edition a").text().trim(); int downCount = Integer.valueOf(RegexUtil.getMatchStr(matchRow.select(".dt_count").text(), "([\\d]+)")); String ext = ""; for(String extName : AppConfig.subExtNames) { //if(StrUtil.isNotEmpty(RegexUtil.getMatchStr(html, "(>"+extName+"<)", Pattern.CASE_INSENSITIVE))) { if(htmlLower.contains(">"+extName+"<")) { ext += extName; ext += ","; } } if(ext.endsWith(",")) { ext=ext.substring(0, ext.length()-1); }else { ext="其它"; } String lang = ""; String[] langList = new String[] {"双语", "简体", "繁体", "英文"}; for(String langName : langList) { if(htmlLower.contains(">"+langName+"<")) { lang += langName; lang += ","; } } if(lang.endsWith(",")) { lang=lang.substring(0, lang.length()-1); }else { lang="其它"; } Elements labels = matchRow.select(".label"); StringBuffer labelInfo = new StringBuffer(); labels.forEach(element ->{ labelInfo.append(element.text() + ","); }); if(labelInfo.length() > 0) { labelInfo.delete(labelInfo.length()-1, labelInfo.length()); } String zimuzu = matchRow.select("a.gray").text(); JSONObject dataRow = new JSONObject(); dataRow.put("url", downUrl); dataRow.put("title", title); dataRow.put("ext", ext); dataRow.put("lang",lang); dataRow.put("rate", "-"); dataRow.put("downCount", downCount); dataRow.put("labelInfo", labelInfo); dataRow.put("zimuzu", zimuzu); detailList.add(dataRow); } return detailList; }