Java Code Examples for com.alibaba.fastjson.JSONObject#containsKey()
The following examples show how to use
com.alibaba.fastjson.JSONObject#containsKey() .
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: Token.java From weixin4j with Apache License 2.0 | 6 votes |
/** * 通过微信公众平台返回JSON对象创建凭证对象 * * <p> * 正常情况下,微信会返回下述JSON数据包给公众号: * {"access_token":"ACCESS_TOKEN","expires_in":7200}</p> * * @param jsonObj JSON数据包 * @throws org.weixin4j.WeixinException 微信操作异常 */ public Token(JSONObject jsonObj) throws WeixinException { this.access_token = jsonObj.getString("access_token"); //根据当前时间的毫秒数+获取的秒数计算过期时间 int expiresIn = jsonObj.getIntValue("expires_in"); if (jsonObj.containsKey("create_time")) { //获取创建时间 long createTime = jsonObj.getLong("create_time"); if (createTime > 0) { //设定指定日期 setExpires_in(expiresIn, createTime); return; } } setExpires_in(expiresIn); }
Example 2
Source File: ConversationAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 清除会话状态 * @param chatidOrUserid 会话ID或用户ID * @param type 类型:single或group 即 群聊或单聊 * @param opUser 操作人ID * @param accessToken * @return */ public static MsgResponse clearnotify(String chatidOrUserid,String type,String opUser,String accessToken){ MsgResponse msgResponse = new MsgResponse(); String errmsg = "ok"; int result = -1; JSONObject jsonContent = new JSONObject(); JSONObject chat = new JSONObject(); chat.put("id", chatidOrUserid); chat.put("type", type); jsonContent.put("chat", chat); jsonContent.put("op_user", opUser); String url = conversation_clearnotifay_url.replace("ACCESS_TOKEN", accessToken); JSONObject jsonObject = HttpUtil.sendPost(url,jsonContent.toJSONString()); if(null != jsonObject) { int errcode = jsonObject.getIntValue("errcode"); if(jsonObject.containsKey("errmsg")){ errmsg = jsonObject.getString("errmsg"); } result = errcode; } msgResponse.setErrcode(result); msgResponse.setErrmsg(errmsg); return msgResponse; }
Example 3
Source File: VideoFormat.java From java-youtube-downloader with Apache License 2.0 | 6 votes |
public VideoFormat(JSONObject json) { super(json); fps = json.getInteger("fps"); qualityLabel = json.getString("qualityLabel"); if (json.containsKey("size")) { String[] split = json.getString("size").split("x"); width = Integer.parseInt(split[0]); height = Integer.parseInt(split[1]); } else { width = json.getInteger("width"); height = json.getInteger("height"); } VideoQuality videoQuality = null; if (json.containsKey("quality")) { try { videoQuality = VideoQuality.valueOf(json.getString("quality")); } catch (IllegalArgumentException ignore) { } } this.videoQuality = videoQuality; }
Example 4
Source File: JsonUtils.java From lorne_core with Apache License 2.0 | 6 votes |
public static double getDouble(String json, String key, double defaultVal) { JSONObject jsonObject = JSONObject.parseObject(json); try { if (jsonObject == null) { return defaultVal; } if (jsonObject.containsKey(key)) { return jsonObject.getDouble(key); } else { return defaultVal; } } catch (Exception e) { return defaultVal; } }
Example 5
Source File: RedirectImpl.java From tephra with MIT License | 6 votes |
@Override public void onStorageChanged(String path, String absolutePath) { String string = io.readAsString(absolutePath); JSONObject object = json.toObject(string); if (object == null) { logger.warn(null, "读取转发配置[{}:{}]失败!", path, string); return; } uri = object.containsKey("uri") ? object.getString("uri") : "/tephra/ctrl-http/redirect"; hosts = toSet(object, "hosts"); regexes = toSet(object, "regexes"); if (logger.isInfoEnable()) logger.info("更新转发配置[{}:{}:{}]。", uri, hosts.toString(), regexes.toString()); }
Example 6
Source File: WeiXinController.java From javabase with Apache License 2.0 | 6 votes |
@RequestMapping("/weixin/auth") public String weiXinAuth(Model model, String code, String token) throws Exception { String url = String.format(weiXinConfig.getAccessTokenUrl(), weiXinConfig.getAppid(), weiXinConfig.getSecret(), code); String result = Request.Get(url).execute().returnContent().asString(); if (StringUtils.isNotEmpty(result)) { JSONObject jsonObject = JSONObject.parseObject(result); if (!jsonObject.containsKey("errcode")) { String openid = jsonObject.getString("openid"); String accessToken = jsonObject.getString("access_token"); String userInfoUrl = String.format(weiXinConfig.getUserinfoUrl(), accessToken, openid); String userInfoResult = Request.Get(userInfoUrl).execute().returnContent() .asString(Charset.forName("utf-8")); log.info("userInfoResult=" + userInfoResult); redisTemplate.opsForValue().set(token, "1",2, TimeUnit.MINUTES); redisTemplate.opsForValue().set(token + "info", userInfoResult, 30, TimeUnit.MINUTES); model.addAttribute("result","登录成功!"); }else{ model.addAttribute("result","登录失败!"); } } // return "weixin/loginResult"; return "redirect:https://ggj2010.bid/tiebaimage"; }
Example 7
Source File: AssetImportSMOImpl.java From MicroCommunity with Apache License 2.0 | 6 votes |
/** * 查询存在的房屋信息 * room.queryRooms * * @param pd * @param result * @param parkingSpace * @return */ private JSONObject getExistsParkSpace(IPageData pd, ComponentValidateResult result, ImportParkingSpace parkingSpace) { String apiUrl = ""; ResponseEntity<String> responseEntity = null; apiUrl = ServiceConstant.SERVICE_API_URL + "/api/parkingSpace.queryParkingSpaces?page=1&row=1&communityId=" + result.getCommunityId() + "&num=" + parkingSpace.getPsNum(); responseEntity = this.callCenterService(restTemplate, pd, "", apiUrl, HttpMethod.GET); if (responseEntity.getStatusCode() != HttpStatus.OK) { //跳过 保存单元信息 return null; } JSONObject savedParkingSpaceInfoResults = JSONObject.parseObject(responseEntity.getBody()); if (!savedParkingSpaceInfoResults.containsKey("parkingSpaces") || savedParkingSpaceInfoResults.getJSONArray("parkingSpaces").size() != 1) { return null; } JSONObject savedParkingSpaceInfo = savedParkingSpaceInfoResults.getJSONArray("parkingSpaces").getJSONObject(0); return savedParkingSpaceInfo; }
Example 8
Source File: FlipImpl.java From tephra with MIT License | 5 votes |
@Override public void zero(XSLFSimpleShape xslfSimpleShape, JSONObject shape) { if (!shape.containsKey("flip")) return; JSONObject flip = shape.getJSONObject("flip"); if (flip.containsKey("horizontal")) xslfSimpleShape.setFlipHorizontal(!xslfSimpleShape.getFlipHorizontal()); if (flip.containsKey("vertical")) xslfSimpleShape.setFlipVertical(!xslfSimpleShape.getFlipVertical()); }
Example 9
Source File: SaveOwnerListener.java From MicroCommunity with Apache License 2.0 | 5 votes |
@Override protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) { //生成memberId generateMemberId(reqJson); //添加小区楼 ownerBMOImpl.addOwner(reqJson, context); if ("1001".equals(reqJson.getString("ownerTypeCd"))) { //小区楼添加到小区中 ownerBMOImpl.addCommunityMember(reqJson, context); } //有房屋信息,则直接绑定房屋和 业主的关系 if (reqJson.containsKey("roomId")) { //添加单元信息 ownerBMOImpl.sellRoom(reqJson, context); //添加物业费用信息 ownerBMOImpl.addPropertyFee(reqJson, context); } if (reqJson.containsKey("ownerPhoto") && !StringUtils.isEmpty(reqJson.getString("ownerPhoto"))) { FileDto fileDto = new FileDto(); fileDto.setFileId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_file_id)); fileDto.setFileName(fileDto.getFileId()); fileDto.setContext(reqJson.getString("ownerPhoto")); fileDto.setSuffix("jpeg"); fileDto.setCommunityId(reqJson.getString("communityId")); String fileName = fileInnerServiceSMOImpl.saveFile(fileDto); reqJson.put("ownerPhotoId", fileDto.getFileId()); reqJson.put("fileSaveName", fileName); ownerBMOImpl.addOwnerPhoto(reqJson, context); } }
Example 10
Source File: LoginService.java From javabase with Apache License 2.0 | 5 votes |
public UserInfo validateAndGetUserInfo(String p, String timestamp, String appkey) throws Exception { //解密 String decryptParam=DesUtil.decrypt(p,appkey+timestamp); JSONObject userInfoJson= (JSONObject) JSON.parse(decryptParam); if(userInfoJson.containsKey(LOGIN_NAME)&&userInfoJson.containsKey(PASSWORD)){ return JSON.parseObject(decryptParam,UserInfo.class); }else{ //参数异常 throw new BizException(resultCodeConfiguration.getParamErrorCode(), resultCodeConfiguration.getParamErrorMsg()); } }
Example 11
Source File: TemplateImpl.java From tephra with MIT License | 5 votes |
@Override public void process(String name, Object data, OutputStream outputStream) throws IOException { if (!(data instanceof JSONObject)) return; JSONObject object = (JSONObject) data; if (object.containsKey("filename")) response.setHeader("Content-Disposition", "attachment; filename*=" + context.getCharset(null) + "''" + coder.encodeUrl(object.getString("filename"), null) + ".pptx"); pptx.write(object, outputStream); }
Example 12
Source File: AuthWeiboRequest.java From JustAuth with MIT License | 5 votes |
@Override public AuthResponse revoke(AuthToken authToken) { String response = doGetRevoke(authToken); JSONObject object = JSONObject.parseObject(response); if (object.containsKey("error")) { return AuthResponse.builder() .code(AuthResponseStatus.FAILURE.getCode()) .msg(object.getString("error")) .build(); } // 返回 result = true 表示取消授权成功,否则失败 AuthResponseStatus status = object.getBooleanValue("result") ? AuthResponseStatus.SUCCESS : AuthResponseStatus.FAILURE; return AuthResponse.builder().code(status.getCode()).msg(status.getMsg()).build(); }
Example 13
Source File: WeiXinQrcodeUtil.java From jeewx-boot with Apache License 2.0 | 5 votes |
/** * 调取微信接口获取临时的二维码地址 * @param jwid * @param sceneId * @param expireSeconds * @return */ public static String getTemporaryQrcode(String jwid, String sceneId, Integer expireSeconds) { //TODO 获取accessTolken String accessToken=WeiXinHttpUtil.getRedisWeixinToken(jwid); try { logger.info("生成带参数二维码请求参数:jwid={},sceneId={},expireSeconds={}.",new Object[]{jwid,sceneId,expireSeconds}); //请求参数 StringBuffer requestStr = new StringBuffer(); requestStr.append("{\"action_info\":{\"scene\":{\"scene_id\":") .append(sceneId) .append("}},\"action_name\":\"QR_SCENE\",\"expire_seconds\":") .append(expireSeconds).append("}"); logger.info("生成带参数二维码接口请求参数:{}.",new Object[]{requestStr.toString()}); //调取微信接口 String jsonStr = HttpUtils.doPostJson("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="+ accessToken, requestStr.toString()); logger.info("生成带参数二维码接口返回参数:{}.",new Object[]{jsonStr}); //解析返回JSON if (jsonStr != null) { JSONObject jsonObject = JSONObject.parseObject(jsonStr); if (jsonObject.containsKey("ticket")) { String ticket = jsonObject.getString("ticket"); String encode = URLEncoder.encode(ticket); return "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="+ encode; } // if(jsonObject.containsKey("url")){ // return jsonObject.getString("url").replace("\\/", "/"); // } } } catch (Exception e) { logger.info("生成带参数二维码接口错误:{}.",new Object[]{e}); return null; } return null; }
Example 14
Source File: RpcClient.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 5 votes |
private Boolean messageValidate(JSONObject parseObject) { if (parseObject != null && parseObject.containsKey("error")) { String error = parseObject.getString("error"); if (StringUtil.isNotEmpty(error)) { System.err.println("rpc error:" + parseObject); logger.error("rpc error:" + parseObject); return true; } else { return false; } } return false; }
Example 15
Source File: SaveOwnerListener.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 生成小区楼ID * * @param paramObj 请求入参数据 */ private void generateMemberId(JSONObject paramObj) { String memberId = GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_ownerId); paramObj.put("memberId", memberId); if (!paramObj.containsKey("ownerId") || "1001".equals(paramObj.getString("ownerTypeCd"))) { paramObj.put("ownerId", memberId); } }
Example 16
Source File: ModelHelperImpl.java From tephra with MIT License | 5 votes |
private <T extends Model> T fromJson(JSONObject json, ModelTable modelTable, Class<T> modelClass) { T model = BeanFactory.getBean(modelClass); if (json.containsKey("id")) model.setId(json.getString("id")); return toModel(modelTable, model, json); }
Example 17
Source File: AVIMImageMessage.java From java-unified-sdk with Apache License 2.0 | 5 votes |
@Override protected void parseAdditionalMetaData(final Map<String, Object> meta, JSONObject response) { if (null == meta || null == response) { return; } if (response.containsKey(FORMAT)) { meta.put(FORMAT, response.getString(FORMAT)); } if (response.containsKey(IMAGE_HEIGHT)) { meta.put(IMAGE_HEIGHT, response.getInteger(IMAGE_HEIGHT)); } if (response.containsKey(IMAGE_WIDTH)) { meta.put(IMAGE_WIDTH, response.getInteger(IMAGE_WIDTH)); } }
Example 18
Source File: X8CameraTakePhotoSettingContoller.java From FimiX8-RE with MIT License | 4 votes |
public void initData(JSONObject rtJson) { if (!(rtJson == null || rtJson.get("param") == null)) { JSONArray paramArray = rtJson.getJSONArray("param"); if (paramArray != null && paramArray.size() > 0) { X8CameraParamsValue paramsValue = X8CameraParamsValue.getInstance(); for (int j = 0; j < paramArray.size(); j++) { JSONObject object = paramArray.getJSONObject(j); if (object != null) { if (object.containsKey("video_quality")) { this.paramMap.put("video_quality", object.getString("video_quality")); paramsValue.getCurParamsJson().setVideo_quality(object.getString("video_quality")); } else if (object.containsKey("video_resolution")) { this.paramMap.put("video_resolution", object.getString("video_resolution")); paramsValue.getCurParamsJson().setVideo_resolution(object.getString("video_resolution")); } else if (object.containsKey(CameraJsonCollection.KEY_VIDEO_TIMELAPSE)) { this.paramMap.put(CameraJsonCollection.KEY_VIDEO_TIMELAPSE, object.getString(CameraJsonCollection.KEY_VIDEO_TIMELAPSE)); paramsValue.getCurParamsJson().setVideo_timelapse(object.getString(CameraJsonCollection.KEY_VIDEO_TIMELAPSE)); } else if (object.containsKey(CameraJsonCollection.KEY_PHOTO_TIMELAPSE)) { this.paramMap.put(CameraJsonCollection.KEY_PHOTO_TIMELAPSE, object.getString(CameraJsonCollection.KEY_PHOTO_TIMELAPSE)); paramsValue.getCurParamsJson().setPhoto_timelapse(object.getString(CameraJsonCollection.KEY_PHOTO_TIMELAPSE)); } else if (object.containsKey(CameraJsonCollection.KEY_RECORD_MODE)) { this.paramMap.put(CameraJsonCollection.KEY_RECORD_MODE, object.getString(CameraJsonCollection.KEY_RECORD_MODE)); paramsValue.getCurParamsJson().setRecord_mode(object.getString(CameraJsonCollection.KEY_RECORD_MODE)); } else if (object.containsKey("capture_mode")) { this.paramMap.put("capture_mode", object.getString("capture_mode")); paramsValue.getCurParamsJson().setCapture_mode(object.getString("capture_mode")); } else if (object.containsKey("photo_format")) { this.paramMap.put("photo_format", object.getString("photo_format")); paramsValue.getCurParamsJson().setPhoto_format(object.getString("photo_format")); } else if (object.containsKey("photo_size")) { this.paramMap.put("photo_size", object.getString("photo_size")); paramsValue.getCurParamsJson().setPhoto_size(object.getString("photo_size")); } else if (object.containsKey("ae_bias")) { this.paramMap.put("ae_bias", object.getString("ae_bias")); paramsValue.getCurParamsJson().setAe_bias(object.getString("ae_bias")); } else if (object.containsKey(CameraJsonCollection.KEY_AE_ISO)) { this.paramMap.put(CameraJsonCollection.KEY_AE_ISO, object.getString(CameraJsonCollection.KEY_AE_ISO)); paramsValue.getCurParamsJson().setIso(object.getString(CameraJsonCollection.KEY_AE_ISO)); } else if (object.containsKey(CameraJsonCollection.KEY_DE_CONTROL_TYPE)) { this.paramMap.put(CameraJsonCollection.KEY_DE_CONTROL_TYPE, object.getString(CameraJsonCollection.KEY_DE_CONTROL_TYPE)); paramsValue.getCurParamsJson().setDe_control(object.getString(CameraJsonCollection.KEY_DE_CONTROL_TYPE)); } else if (object.containsKey(CameraJsonCollection.KEY_SHUTTER_TIME)) { this.paramMap.put(CameraJsonCollection.KEY_SHUTTER_TIME, object.getString(CameraJsonCollection.KEY_SHUTTER_TIME)); paramsValue.getCurParamsJson().setShutter_time(object.getString(CameraJsonCollection.KEY_SHUTTER_TIME)); } else if (object.containsKey("awb")) { this.paramMap.put("awb", object.getString("awb")); paramsValue.getCurParamsJson().setAwb(object.getString("awb")); } else if (object.containsKey(CameraJsonCollection.KEY_METERMING_MODE)) { this.paramMap.put(CameraJsonCollection.KEY_METERMING_MODE, object.getString(CameraJsonCollection.KEY_METERMING_MODE)); paramsValue.getCurParamsJson().setMetering_mode(object.getString(CameraJsonCollection.KEY_METERMING_MODE)); } else if (object.containsKey(CameraJsonCollection.KEY_DIGITAL_EFFECT)) { this.paramMap.put(CameraJsonCollection.KEY_DIGITAL_EFFECT, object.getString(CameraJsonCollection.KEY_DIGITAL_EFFECT)); paramsValue.getCurParamsJson().setDigital_effect(object.getString(CameraJsonCollection.KEY_DIGITAL_EFFECT)); } else if (object.containsKey("saturation")) { this.paramMap.put("saturation", object.getString("saturation")); paramsValue.getCurParamsJson().setSaturation(object.getString("saturation")); } else if (object.containsKey("contrast")) { this.paramMap.put("contrast", object.getString("contrast")); paramsValue.getCurParamsJson().setContrast(object.getString("contrast")); } else if (object.containsKey("sharpness")) { this.paramMap.put("sharpness", object.getString("sharpness")); paramsValue.getCurParamsJson().setSharpness(object.getString("sharpness")); } else if (object.containsKey("system_type")) { this.paramMap.put("system_type", object.getString("system_type")); paramsValue.getCurParamsJson().setSystem_type(object.getString("system_type")); } else if (object.containsKey(CameraJsonCollection.KEY_CAMERA_STYLE)) { this.paramMap.put(CameraJsonCollection.KEY_CAMERA_STYLE, object.getString(CameraJsonCollection.KEY_CAMERA_STYLE)); } } } } } if (this.paramController != null) { this.paramController.updateMode(CameraParamStatus.modelStatus, this.paramMap); } this.tokenEnable = true; }
Example 19
Source File: AuthWeChatOpenRequest.java From JustAuth with MIT License | 4 votes |
/** * 检查响应内容是否正确 * * @param object 请求响应内容 */ private void checkResponse(JSONObject object) { if (object.containsKey("errcode")) { throw new AuthException(object.getIntValue("errcode"), object.getString("errmsg")); } }
Example 20
Source File: AVIMMessage.java From java-unified-sdk with Apache License 2.0 | 4 votes |
public static AVIMMessage parseJSON(JSONObject jsonObject) { if (null == jsonObject) { return null; } AVIMMessage message; if (jsonObject.containsKey("binaryMsg")) { AVIMBinaryMessage binaryMessage = new AVIMBinaryMessage(); Object binValue = jsonObject.get("binaryMsg"); if (binValue instanceof String) { String binString = (String) jsonObject.get("binaryMsg"); binaryMessage.setBytes(Base64Decoder.decodeToBytes(binString)); } else if (binValue instanceof byte[]){ binaryMessage.setBytes((byte[]) binValue); } message = binaryMessage; } else if (jsonObject.containsKey("typeMsgData")) { message = new AVIMMessage(); Object typedMsgData = jsonObject.get("typeMsgData"); if (typedMsgData instanceof String) { message.setContent((String) typedMsgData); } else { message.setContent(JSON.toJSONString(typedMsgData)); } } else { message = new AVIMMessage(); message.setContent((String) jsonObject.get("msg")); } if (jsonObject.containsKey("clientId")) { message.setCurrentClient((String) jsonObject.get("clientId")); } if (jsonObject.containsKey("uniqueToken")) { message.setUniqueToken((String) jsonObject.get("uniqueToken")); } if (jsonObject.containsKey("io")) { message.setMessageIOType(AVIMMessageIOType.getMessageIOType((int) jsonObject.get("io"))); } if (jsonObject.containsKey("status")) { message.setMessageStatus(AVIMMessageStatus.getMessageStatus((int) jsonObject.get("status"))); } if (jsonObject.containsKey("timestamp")) { message.setTimestamp(((Number) jsonObject.get("timestamp")).longValue()); } if (jsonObject.containsKey("ackAt")) { message.setDeliveredAt(((Number) jsonObject.get("ackAt")).longValue()); } if (jsonObject.containsKey("readAt")) { message.setReadAt(((Number) jsonObject.get("readAt")).longValue()); } if (jsonObject.containsKey("patchTimestamp")) { message.setUpdateAt(((Number) jsonObject.get("patchTimestamp")).longValue()); } if (jsonObject.containsKey("mentionAll")) { message.setMentionAll((boolean) jsonObject.get("mentionAll")); } if (jsonObject.containsKey("mentionPids")) { message.setMentionList((List<String>) jsonObject.get("mentionPids")); } if (jsonObject.containsKey("id")) { message.setMessageId((String) jsonObject.get("id")); } if (jsonObject.containsKey("from")) { message.setFrom((String) jsonObject.get("from")); } if (jsonObject.containsKey("conversationId")) { message.setConversationId((String) jsonObject.get("conversationId")); } if (jsonObject.containsKey("typeMsgData")) { message = AVIMMessageManager.parseTypedMessage(message); } return message; }