Java Code Examples for net.sf.json.JSONObject#getString()
The following examples show how to use
net.sf.json.JSONObject#getString() .
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: ConceptMapping.java From Criteria2Query with Apache License 2.0 | 6 votes |
public String[] getCloestConceptByUsagi(String term,String domain){ String[] res=new String[3]; JSONObject jo=new JSONObject(); jo.accumulate("term", StringUtil.cleanASCII(term)); jo.accumulate("domain", domain); String result=HttpUtil.doPost(usagi, jo.toString()); System.out.println(jo.toString()); System.out.println("result="+result); JSONObject bestconcept=JSONObject.fromObject(result); System.out.println("matchScore="+bestconcept.getDouble("matchScore")); String matchs=String.format("%.2f", bestconcept.getDouble("matchScore")*100); JSONObject concept_jo=bestconcept.getJSONObject("concept"); Integer cId=concept_jo.getInt("conceptId"); String conceptname=concept_jo.getString("conceptName"); res[0]=String.valueOf(cId); res[1]=conceptname; res[2]=matchs; return res; }
Example 2
Source File: Engine.java From acunetix-plugin with MIT License | 6 votes |
public Boolean checkScanExist(String scanId) { try { JSONArray scans = getScans(); for (int i = 0; i < scans.size(); i++) { JSONObject item = scans.getJSONObject(i); String id = item.getString("scan_id"); if (id.equals(scanId)) { return true; } } } catch (IOException e){ e.printStackTrace(); } return false; }
Example 3
Source File: UserData.java From anychat with MIT License | 6 votes |
public UserData(JSONObject userData) { if (userData.containsKey("userId")) { this.userId = userData.getString("userId"); } if (userData.containsKey("userRealName")) { this.userRealName = userData.getString("userRealName"); } if (userData.containsKey("userGroupTopId")) { this.userGroupTopId = userData.getString("userGroupTopId"); } if (userData.containsKey("userRole")) { this.userRole = userData.getInt("userRole"); } if (userData.containsKey("userImgUrl")) { this.userImgUrl = userData.getString("userImgUrl"); } }
Example 4
Source File: Engine.java From acunetix-plugin with MIT License | 6 votes |
public String getTargetName(String targetId) throws IOException { JSONArray targets = getTargets(); for (int i = 0; i < targets.size(); i++) { JSONObject item = targets.getJSONObject(i); String target_id = item.getString("target_id"); if (target_id.equals(targetId)) { String address = item.getString("address"); String description = item.getString("description"); String target_name = address; if (description.length() > 0) { if (description.length() > 100) { description = description.substring(0, 100); } target_name += " (" + description + ")"; } return target_name; } } return null; }
Example 5
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 删除永久素材 (经测试,该方法调用接口地址不对) * * @param accesstoken * @param mediaId * 图文集合,数量不大于10 * @return WxArticlesRespponseByMaterial 上传图文消息素材返回结果 * @throws WexinReqException */ public static void deleteArticlesByMaterial(String accesstoken,String mediaId) throws WexinReqException { if (accesstoken != null&&StringUtils.isNotEmpty(mediaId)) { String requestUrl = material_get_material_url.replace("ACCESS_TOKEN", accesstoken); WxArticlesRequestByMaterial wxArticlesRequestByMaterial = new WxArticlesRequestByMaterial(); wxArticlesRequestByMaterial.setMediaId(mediaId); JSONObject obj = JSONObject.fromObject(wxArticlesRequestByMaterial); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); if (result.has("errcode")&&result.get("errcode")!="0") { logger.error("删除消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("删除消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } } }
Example 6
Source File: JwMenuAPI.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 删除所有的菜单 * @param accessToken * @return * @throws WexinReqException */ public static String deleteMenu(String accessToken) throws WexinReqException{ MenuDelete m = new MenuDelete(); m.setAccess_token(accessToken); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(m); String msg = result.getString(WeiXinConstant.RETURN_ERROR_INFO_MSG); return msg; }
Example 7
Source File: BaiduFanyi.java From squirrelAI with Apache License 2.0 | 5 votes |
public static String getBaiduFanyi(String text) { int intMath = 0; String md5 = ""; String returnData = ""; try { intMath = (int) (Math.random() * 100); md5 = setMD5(appid + text + String.valueOf(intMath) + key); connection = Jsoup.connect("http://api.fanyi.baidu.com/api/trans/vip/translate"); connection.header("Content-Type", "application/json"); connection.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); connection.data("q", text); connection.data("from", "auto"); connection.data("to", "auto"); connection.data("appid", appid); connection.data("salt", String.valueOf(intMath)); connection.data("sign", md5); connection.ignoreContentType(true); connection.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"); connection.timeout(5000); document = connection.post(); String strDocJosn = document.text(); JSONObject jsonObject = JSONObject.fromObject(strDocJosn); JSONArray jsonArray = jsonObject.getJSONArray("trans_result"); for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject1 = jsonArray.getJSONObject(i); returnData = jsonObject1.getString("dst"); } } catch (Exception e) { e.printStackTrace(); } return returnData; }
Example 8
Source File: AlipayCoreService.java From jeewx with Apache License 2.0 | 5 votes |
/** * 关键字消息回复 * @param bizContent * @return */ private String doSendKeyMessage(JSONObject bizContent) { // 取得发起请求的支付宝账号id final String fromUserId = bizContent.getString("FromUserId"); final String content = bizContent.getJSONObject("Text").getString("Content"); //update-begin--author:zhangjiaqiang Date:20161108 for:#1487 【开源项目】开源支付窗服务窗单公众号项目 String responseMsg = alipayKeyWordDealInterfaceService.dealKeyMessage(content, alipayAccountService.getAccount().getId(), fromUserId); //update-end--author:zhangjiaqiang Date:20161108 for:#1487 【开源项目】开源支付窗服务窗单公众号项目 return sendMsg(responseMsg, bizContent,content,"文本消息"); }
Example 9
Source File: JwTemplateMessageAPI.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 添加模板信息 * @param accessToken * @param template_id_short * @return * @throws WexinReqException */ public static String addTemplate(String accessToken,String template_id_short) throws WexinReqException{ IndustryTemplateAdd t = new IndustryTemplateAdd(); t.setAccess_token(accessToken); t.setTemplate_id_short(template_id_short); JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(t); String msg = result.getString(WeiXinConstant.RETURN_ERROR_INFO_MSG); if("ok".equalsIgnoreCase(msg)){ msg = result.getString("template_id"); } return msg; }
Example 10
Source File: SystemService.java From ApiManager with GNU Affero General Public License v3.0 | 5 votes |
private String compress(String compressUrl, String baseFileUrl, String fileUrl) throws Exception { String compressText = null; String compressResult = null; try { String cssSource = Tools.readFile(baseFileUrl + fileUrl); compressText = HttpPostGet.postBody(compressUrl, cssSource, null, 5000); JSONObject jsonObject = JSONObject.fromObject(compressText); compressResult = jsonObject.getString("result"); Tools.staticize(compressResult, baseFileUrl + fileUrl); } catch (Throwable e){ log.error("压缩js、css异常,compressText:" + compressText, e); throw e; } return compressResult; }
Example 11
Source File: WeixinTagController.java From jeewx-boot with Apache License 2.0 | 5 votes |
/** * 编辑 * @return */ @RequestMapping(value = "/doEdit",method ={RequestMethod.GET, RequestMethod.POST}) @ResponseBody public AjaxJson doEdit(@ModelAttribute WeixinTag weixinTag,HttpServletRequest request){ AjaxJson j = new AjaxJson(); //update-begin--Author:zhangweijian Date: 20180903 for:提示信息优化 JSONObject jsonObj=null; try { //获取accessToken String jwid=request.getSession().getAttribute("jwid").toString(); String accessToken=WeiXinHttpUtil.getRedisWeixinToken(jwid); //调用编辑标签接口 String requestUrl=update_tag_url.replace("ACCESS_TOKEN", accessToken); String name="{\"tag\":{\"id\":\""+weixinTag.getTagid()+"\",\"name\":\""+weixinTag.getName()+"\"}}"; jsonObj=WeixinUtil.httpRequest(requestUrl,"POST",name); //接口返回信息处理 j=returnJson(jsonObj); //成功则将编辑的标签信息更新到标签表 if(j.isSuccess()==true){ weixinTagService.doEdit(weixinTag); j.setMsg("标签编辑成功!"); } } catch (Exception e) { log.error(e.getMessage()); String errcode=jsonObj.getString("errcode"); j.setSuccess(false); j.setMsg("标签编辑失败!错误码:<a target='_blank' href='https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234'>"+errcode+"</a>"); } //update-end--Author:zhangweijian Date: 20180903 for:提示信息优化 return j; }
Example 12
Source File: SQLMapInner.java From TrackRay with GNU General Public License v3.0 | 5 votes |
public boolean newTask(){ HttpResponse req = get(this.server + "task/new"); if (req!=null){ JSONObject json = toJSON(req.body()); this.taskid = json.getString("taskid"); log.info("创建了一个SQLMAP任务:" + taskid); return true; } return false; }
Example 13
Source File: DashboardBuilder.java From environment-dashboard-plugin with MIT License | 5 votes |
@Override public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { numberOfDays = formData.getString("numberOfDays"); if (numberOfDays == null || numberOfDays.equals("")) { numberOfDays = "30"; } save(); return super.configure(req, formData); }
Example 14
Source File: DifferentialClient.java From phabricator-jenkins-plugin with MIT License | 5 votes |
/** * Fetch the commit message for the revision. This isn't available on the diff, so it requires a separate query. * * @param revisionID The ID of the revision, e.g. for "D123" this would be "123" * @return A \n-separated string of the commit message * @throws ConduitAPIException * @throws IOException */ public String getCommitMessage(String revisionID) throws ConduitAPIException, IOException { // if no revision ID return null if (revisionID == null) { return ""; } JSONObject params = new JSONObject().element("revision_id", revisionID); JSONObject query = callConduit("differential.getcommitmessage", params); // NOTE: When you run this with `arc call-conduit dfferential.getcommitmessage` (from the command-line), // it comes back as "response". But it's "result" when running through this conduit API. return query.getString("result"); }
Example 15
Source File: WeixinTagController.java From jeewx-boot with Apache License 2.0 | 4 votes |
/** * @功能:批量为粉丝打标签 * @param response * @param request * @param tagid * @param openids * @return */ @RequestMapping(value="batchtagging",method = {RequestMethod.GET,RequestMethod.POST}) @ResponseBody public AjaxJson batchtagging(HttpServletResponse response,HttpServletRequest request, @RequestParam String tagid,@RequestParam String openids){ AjaxJson j = new AjaxJson(); //update-begin--Author:zhangweijian Date: 20180903 for:提示信息优化 JSONObject jsonObj=null; try { //获取accessToken String jwid=request.getSession().getAttribute("jwid").toString(); String accessToken=WeiXinHttpUtil.getRedisWeixinToken(jwid); String requestUrl=batchtagging_tag_url.replace("ACCESS_TOKEN", accessToken); //调用批量为用户打标签接口 String[] openidList=openids.split(","); String openList=""; for(int i=0;i<openidList.length;i++){ if(i==openidList.length-1){ openList+='"'+openidList[i]+'"'; }else{ openList+='"'+openidList[i]+'"'+","; } } String name="{\"openid_list\":["+openList+"],\"tagid\":"+tagid+"}"; jsonObj=WeixinUtil.httpRequest(requestUrl,"POST",name); //接口返回信息处理 j=returnJson(jsonObj); //将标签同步到本地数据库当中 if(j.isSuccess()==true){ for(int i=0;i<openidList.length;i++){ WeixinGzuser gzUser=weixinGzuserService.queryByOpenId(openidList[i],jwid); //判断用户是否有无标签 if(StringUtils.isEmpty(gzUser.getTagidList())){ if(i==openidList.length-1){ gzUser.setTagidList(tagid); }else{ gzUser.setTagidList(tagid+","); } }else{ String[] tags=gzUser.getTagidList().split(","); boolean flag=false; for(int t=0;t<tags.length;t++){ //判断用户是否存在当前标签,存在不处理,不存在则添加 if(!tagid.equals(tags[t])){ flag=true; }else{ flag=false; break; } } if(flag){ gzUser.setTagidList(gzUser.getTagidList()+","+tagid); } } weixinGzuserService.doEdit(gzUser); } j.setMsg("批量打标签成功"); } } catch (Exception e) { log.error(e.getMessage()); String errcode=jsonObj.getString("errcode"); j.setSuccess(false); j.setMsg("批量打标签失败!错误码:<a target='_blank' href='https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234'>"+errcode+"</a>"); } //update-end--Author:zhangweijian Date: 20180903 for:提示信息优化 return j; }
Example 16
Source File: WeixinGzuserServiceImpl.java From jeewx-boot with Apache License 2.0 | 4 votes |
@Override public String getFansListTask(String next_openid, String jwid) { //获取微信公众账号的关注粉丝(同步openid) String returnMsg; int total=0; try { returnMsg = "粉丝同步成功,同步粉丝条数:"; //获取token String accessToken=WeiXinHttpUtil.getRedisWeixinToken(jwid); if(StringUtils.isNotEmpty(accessToken)){ //多线程处理数据 ThreadPoolExecutor executor = new ThreadPoolExecutor(10,10,1,TimeUnit.SECONDS,new LinkedBlockingQueue()); List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>(2000); int k=0; //获取粉丝列表信息 String requestUrl=user_List_url.replace("NEXT_OPENID", "").replace("ACCESS_TOKEN", accessToken); while(oConvertUtils.isNotEmpty(next_openid) && k<2000){ k++; //调用接口获取粉丝列表(一次最多拉取10000) JSONObject jsonObj=WeixinUtil.httpRequest(requestUrl, "GET", ""); next_openid=null; //防止死循环 if(jsonObj==null){ continue; } if(!jsonObj.containsKey("errmsg")){ total = jsonObj.getInt("total"); int count=jsonObj.getInt("count"); if(count!=0){ //获取拉取的粉丝的openid JSONArray openIdArr = jsonObj.getJSONObject("data").getJSONArray("openid"); //将粉丝信息存到数据库 futures.add(executor.submit(new SyncFansInfo(jwid,openIdArr))); } next_openid = jsonObj.getString("next_openid"); //使用next_openid继续获取下一页粉丝数据[循环] //update-begin--Author:zhangweijian Date:20181015 for:同步粉丝问题 requestUrl=user_List_url.replace("ACCESS_TOKEN",accessToken).replace("NEXT_OPENID", next_openid); //update-end--Author:zhangweijian Date:20181015 for:同步粉丝问题 } } executor.shutdown(); //update-begin-zhangweijian-----Date:20180809---for:线程池结束判断 while (true) { if (executor.isTerminated()) { break; } Thread.sleep(200); } //update-end-zhangweijian-----Date:20180809---for:线程池结束判断 } } catch (Exception e) { e.printStackTrace(); } return "同步任务已启动,请稍候刷新。公众号粉丝总数:"+total; }
Example 17
Source File: JwPersonalizedMenuAPI.java From jeewx-api with Apache License 2.0 | 4 votes |
/** * 创建个性化菜单 * button 是 一级菜单数组,个数应为1~3个 sub_button 否 二级菜单数组,个数应为1~5个 type 是 菜单的响应动作类型 name 是 菜单标题,不超过16个字节,子菜单不超过40个字节 key click等点击类型必须 菜单KEY值,用于消息接口推送,不超过128字节 url view类型必须 网页链接,用户点击菜单可打开链接,不超过256字节 matchrule 是 菜单匹配规则 group_id 否 用户分组id,可通过用户分组管理接口获取 sex 否 性别:男(1)女(2),不填则不做匹配 client_platform_type 否 客户端版本,当前只具体到系统型号:IOS(1), Android(2),Others(3),不填则不做匹配 country 否 国家信息,是用户在微信中设置的地区,具体请参考地区信息表 province 否 省份信息,是用户在微信中设置的地区,具体请参考地区信息表 city 否 城市信息,是用户在微信中设置的地区,具体请参考地区信息表 language 否 语言信息,是用户在微信中设置的语言,具体请参考语言表: 1、简体中文 "zh_CN" 2、繁体中文TW "zh_TW" 3、繁体中文HK "zh_HK" 4、英文 "en" 5、印尼 "id" 6、马来 "ms" 7、西班牙 "es" 8、韩国 "ko" 9、意大利 "it" 10、日本 "ja" 11、波兰 "pl" 12、葡萄牙 "pt" 13、俄国 "ru" 14、泰文 "th" 15、越南 "vi" 16、阿拉伯语 "ar" 17、北印度 "hi" 18、希伯来 "he" 19、土耳其 "tr" 20、德语 "de" 21、法语 "fr" * @param accessToken * @param menu 的json字符串 * @return menuid */ public static String createMenu(String accessToken,PersonalizedMenu menu){ String msg = ""; if (accessToken != null) { String requestUrl = create_menu.replace("ACCESS_TOKEN", accessToken); JSONObject obj = JSONObject.fromObject(menu); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE); if(error == null){ msg = result.getString("menuid"); }else{ msg = result.getString(WeiXinConstant.RETURN_ERROR_INFO_MSG); } } return msg; }
Example 18
Source File: PRUpdateGHEventSubscriber.java From github-pr-comment-build-plugin with MIT License | 4 votes |
/** * Handles updates of pull requests. * @param event only PULL_REQUEST events * @param payload payload of gh-event. Never blank */ @Override protected void onEvent(GHEvent event, String payload) { JSONObject json = JSONObject.fromObject(payload); // Since we receive both pull request and issue comment events in this same code, // we check first which one it is and set values from different fields JSONObject pullRequest = json.getJSONObject("pull_request"); final String pullRequestUrl = pullRequest.getString("html_url"); Integer pullRequestId = pullRequest.getInt("number"); // Make sure the action is edited String action = json.getString("action"); if (!ACTION_EDITED.equals(action)) { LOGGER.log(Level.FINER, "Pull request action is not edited ({0}) for PR {1}, ignoring", new Object[] { action, pullRequestUrl } ); return; } // Set some values used below final Pattern pullRequestJobNamePattern = Pattern.compile("^PR-" + pullRequestId + "\\b.*$", Pattern.CASE_INSENSITIVE); // Make sure the repository URL is valid String repoUrl = json.getJSONObject("repository").getString("html_url"); Matcher matcher = REPOSITORY_NAME_PATTERN.matcher(repoUrl); if (!matcher.matches()) { LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl); return; } final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(repoUrl); if (changedRepository == null) { LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl); return; } LOGGER.log(Level.FINE, "Received update on PR {1} for {2}", new Object[] { pullRequestId, repoUrl }); ACL.impersonate(ACL.SYSTEM, new Runnable() { @Override public void run() { boolean jobFound = false; for (final SCMSourceOwner owner : SCMSourceOwners.all()) { for (SCMSource source : owner.getSCMSources()) { if (!(source instanceof GitHubSCMSource)) { continue; } GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source; if (gitHubSCMSource.getRepoOwner().equalsIgnoreCase(changedRepository.getUserName()) && gitHubSCMSource.getRepository().equalsIgnoreCase(changedRepository.getRepositoryName())) { for (Job<?, ?> job : owner.getAllJobs()) { if (pullRequestJobNamePattern.matcher(job.getName()).matches()) { if (!(job.getParent() instanceof MultiBranchProject)) { continue; } boolean propFound = false; for (BranchProperty prop : ((MultiBranchProject) job.getParent()).getProjectFactory(). getBranch(job).getProperties()) { if (!(prop instanceof TriggerPRUpdateBranchProperty)) { continue; } propFound = true; ParameterizedJobMixIn.scheduleBuild2(job, 0, new CauseAction(new GitHubPullRequestUpdateCause(pullRequestUrl))); break; } if (!propFound) { LOGGER.log(Level.FINE, "Job {0} for {1}:{2}/{3} does not have a trigger PR update branch property", new Object[] { job.getFullName(), changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName() } ); } jobFound = true; } } } } } if (!jobFound) { LOGGER.log(Level.FINE, "PR update on {0}:{1}/{2} did not match any job", new Object[] { changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName() } ); } } }); }
Example 19
Source File: Engine.java From acunetix-plugin with MIT License | 4 votes |
public String getScanProfile(String scanId) throws IOException { JSONObject jso = doGet(apiUrl + "/scans/" + scanId).jso; return jso.getString("profile_id"); }
Example 20
Source File: Engine.java From acunetix-plugin with MIT License | 4 votes |
private String getReportStatus(String reportId) throws IOException { JSONObject jso = doGet(apiUrl + "/reports/" + reportId).jso; return jso.getString("status"); }