Java Code Examples for com.alibaba.fastjson.JSONObject#getJSONObject()
The following examples show how to use
com.alibaba.fastjson.JSONObject#getJSONObject() .
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: SaveStoreInfoListener.java From MicroCommunity with Apache License 2.0 | 6 votes |
/** * 保存商户属性信息 * * @param business 当前业务 * @param businessStoreAttrs 商户属性 */ private void doSaveBusinessStoreAttrs(Business business, JSONArray businessStoreAttrs) { JSONObject data = business.getDatas(); JSONObject businessStore = data.getJSONObject(StorePo.class.getSimpleName()); for (int storeAttrIndex = 0; storeAttrIndex < businessStoreAttrs.size(); storeAttrIndex++) { JSONObject storeAttr = businessStoreAttrs.getJSONObject(storeAttrIndex); Assert.jsonObjectHaveKey(storeAttr, "attrId", "businessStoreAttr 节点下没有包含 attrId 节点"); if (storeAttr.getString("attrId").startsWith("-")) { String attrId = GenerateCodeFactory.getAttrId(); storeAttr.put("attrId", attrId); } storeAttr.put("bId", business.getbId()); storeAttr.put("storeId", businessStore.getString("storeId")); storeAttr.put("operate", StatusConstant.OPERATE_ADD); storeServiceDaoImpl.saveBusinessStoreAttr(storeAttr); } }
Example 2
Source File: RpcClient.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 6 votes |
/** * @description 获取区间区块头 GetHeaders 该接口用于获取指定高度区间的区块头部信息 * * @param start 开始区块高度 * @param end 结束区块高度 * @param isDetail 是否打印区块详细信息 */ public List<BlockResult> getHeaders(Long start, Long end, boolean isDetail) { JSONObject jsonObject = new JSONObject(); jsonObject.put("start", start); jsonObject.put("end", end); jsonObject.put("isDetail", isDetail); RpcRequest postData = getPostData(RpcMethod.GET_HEADERS); postData.addJsonParams(jsonObject); String result = HttpUtil.httpPostBody(getUrl(), postData.toJsonString()); if (StringUtil.isNotEmpty(result)) { JSONObject parseObject = JSONObject.parseObject(result); if (messageValidate(parseObject)) return null; JSONObject jsonResult = parseObject.getJSONObject("result"); JSONArray jsonArray = jsonResult.getJSONArray("items"); List<BlockResult> blockResultList = new ArrayList<>(); for (int i = 0; i < jsonArray.size(); i++) { JSONObject blockJson = jsonArray.getJSONObject(i); BlockResult blockResult = JSONObject.toJavaObject(blockJson, BlockResult.class); blockResult.setBlockTime(new Date(blockResult.getBlockTime().getTime() * 1000)); blockResultList.add(blockResult); } return blockResultList; } return null; }
Example 3
Source File: DBusRouterKafkaWriteBolt.java From DBus with Apache License 2.0 | 6 votes |
private void effectTopologyTable(JSONObject ctrl, boolean isStart) throws Exception { JSONObject payload = ctrl.getJSONObject("payload"); Integer projectTopoTableId = payload.getInteger("projectTopoTableId"); List<Sink> sinkVos = inner.dbHelper.loadSinks(inner.topologyId, projectTopoTableId); if (sinkVos != null && sinkVos.size() > 0) { for (Sink vo : sinkVos) { String key = StringUtils.joinWith(".", vo.getDsName(), vo.getSchemaName(), vo.getTableName()); topicMap.remove(key); topicMap.put(key, vo.getTopic()); sinksMap.remove(key); sinksMap.put(key, vo.getUrl()); kafkaProducerManager.close(); //String url = vo.getUrl(); /*if (!producerMap.containsKey(url)) { String clientId = StringUtils.joinWith("-", kafkaProducerConf.getProperty("client.id"), String.valueOf(producerMap.size() + 1)); producerMap.put(url, obtainKafkaProducer(url, clientId)); }*/ if (isStart) { String path = StringUtils.joinWith("/", Constants.HEARTBEAT_PROJECT_MONITOR, vo.getProjectName(), inner.topologyId, key); inner.zkHelper.createNode(path); } } } inner.dbHelper.toggleProjectTopologyTableStatus(projectTopoTableId, DBusRouterConstants.PROJECT_TOPOLOGY_TABLE_STATUS_START); logger.info("kafka write bolt effect topology table:{} completed.", projectTopoTableId); }
Example 4
Source File: RpcClient.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 6 votes |
/** * @description 生成随机的seed * * @param lang lang=0:英语,lang=1:简体汉字 * @return seed */ public String seedGen(Integer lang) { RpcRequest postData = getPostData(RpcMethod.GEN_SEED); JSONObject requestParam = new JSONObject(); requestParam.put("lang", lang); postData.addJsonParams(requestParam); String result = HttpUtil.httpPostBody(getUrl(), postData.toJsonString()); if (StringUtil.isNotEmpty(result)) { JSONObject parseObject = JSONObject.parseObject(result); if (messageValidate(parseObject)) return null; JSONObject resultJson = parseObject.getJSONObject("result"); String seed = resultJson.getString("seed"); return seed; } return null; }
Example 5
Source File: RpcClient.java From chain33-sdk-java with BSD 2-Clause "Simplified" License | 6 votes |
/** * @description 导出私钥 * * @param addr 导出私钥的地址 * @return 私钥 */ public String dumpPrivkey(String addr) { RpcRequest postData = getPostData(RpcMethod.DUMP_PRIVKEY); JSONObject requestParam = new JSONObject(); requestParam.put("ReqStr", addr); postData.addJsonParams(requestParam); String requestResult = HttpUtil.httpPostBody(getUrl(), postData.toJsonString()); if (StringUtil.isNotEmpty(requestResult)) { JSONObject parseObject = JSONObject.parseObject(requestResult); if (messageValidate(parseObject)) return null; JSONObject resultObj = parseObject.getJSONObject("result"); String resultStr = resultObj.getString("replystr"); return resultStr; } return null; }
Example 6
Source File: AuthMiRequest.java From JustAuth with MIT License | 5 votes |
@Override protected AuthUser getUserInfo(AuthToken authToken) { // 获取用户信息 String userResponse = doGetUserInfo(authToken); JSONObject userProfile = JSONObject.parseObject(userResponse); if ("error".equalsIgnoreCase(userProfile.getString("result"))) { throw new AuthException(userProfile.getString("description")); } JSONObject object = userProfile.getJSONObject("data"); AuthUser authUser = AuthUser.builder() .rawUserInfo(object) .uuid(authToken.getOpenId()) .username(object.getString("miliaoNick")) .nickname(object.getString("miliaoNick")) .avatar(object.getString("miliaoIcon")) .email(object.getString("mail")) .gender(AuthUserGender.UNKNOWN) .token(authToken) .source(source.toString()) .build(); // 获取用户邮箱手机号等信息 String emailPhoneUrl = MessageFormat.format("{0}?clientId={1}&token={2}", "https://open.account.xiaomi.com/user/phoneAndEmail", config .getClientId(), authToken.getAccessToken()); String emailResponse = new HttpUtils(config.getHttpConfig()).get(emailPhoneUrl); JSONObject userEmailPhone = JSONObject.parseObject(emailResponse); if (!"error".equalsIgnoreCase(userEmailPhone.getString("result"))) { JSONObject emailPhone = userEmailPhone.getJSONObject("data"); authUser.setEmail(emailPhone.getString("email")); } else { Log.warn("小米开发平台暂时不对外开放用户手机及邮箱信息的获取"); } return authUser; }
Example 7
Source File: TagsComponent.java From weixin4j with Apache License 2.0 | 5 votes |
/** * 创建标签 * * <p> * 一个公众号,最多可以创建100个标签。</p> * * @param name 标签名,UTF8编码 * @return 包含标签ID的对象 * @throws org.weixin4j.WeixinException 微信操作异常 */ public Tag create(String name) throws WeixinException { //创建请求对象 HttpsClient http = new HttpsClient(); //拼接参数 JSONObject postTag = new JSONObject(); JSONObject postName = new JSONObject(); postName.put("name", name); postTag.put("tag", postName); //调用获创建标签接口 Response res = http.post("https://api.weixin.qq.com/cgi-bin/tags/create?access_token=" + weixin.getToken().getAccess_token(), postTag); //根据请求结果判定,是否验证成功 JSONObject jsonObj = res.asJSONObject(); //成功返回如下JSON: //{"tag":{"id":134, name":"广东"}} if (jsonObj != null) { if (Configuration.isDebug()) { System.out.println("获取/tags/create返回json:" + jsonObj.toString()); } Object errcode = jsonObj.get("errcode"); if (errcode != null && !errcode.toString().equals("0")) { //返回异常信息 throw new WeixinException(getCause(jsonObj.getIntValue("errcode"))); } else { JSONObject tagJson = jsonObj.getJSONObject("tag"); if (tagJson != null) { return JSONObject.toJavaObject(tagJson, Tag.class); } } } return null; }
Example 8
Source File: FullPullService.java From DBus with Apache License 2.0 | 5 votes |
private String getMonitorNodePath(String dsName, JSONObject reqJson) { String monitorRoot = Constants.FULL_PULL_MONITOR_ROOT; String dbNameSpace = buildSlashedNameSpace(dsName, reqJson); String monitorNodePath; JSONObject projectJson = reqJson.getJSONObject("project"); if (projectJson != null && !projectJson.isEmpty()) { int projectId = projectJson.getIntValue("id"); String projectName = projectJson.getString("name"); monitorNodePath = String.format("%s/%s/%s_%s/%s", monitorRoot, "Projects", projectName, projectId, dbNameSpace); } else { monitorNodePath = buildZkPath(monitorRoot, dbNameSpace); } return monitorNodePath; }
Example 9
Source File: FilterException.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 异常 * @return */ public String toJsonString() { JSONObject exceptionJson = JSONObject.parseObject("{\"exception\":{}"); JSONObject exceptionJsonObj = exceptionJson.getJSONObject("exception"); if (getResult() != null) exceptionJsonObj.putAll(JSONObject.parseObject(result.toString())); exceptionJsonObj.put("exceptionTrace",getMessage()); return exceptionJsonObj.toString(); }
Example 10
Source File: TemplateConfig.java From ES-Fastloader with Apache License 2.0 | 5 votes |
public TemplateConfig(JSONObject root) throws Exception { if(root==null) { throw new Exception("root is null"); } for(String key : root.keySet()) { if(key.equalsIgnoreCase(TEMPLATE_STR)) { template.add((String) root.get(key)); } else if(key.equalsIgnoreCase(INDEX_PATTERNS_STR)) { Object obj = root.get(key); if(obj instanceof JSONArray) { for(Object o : (JSONArray)obj) { template.add(o.toString()); } } else { template.add(obj.toString()); } } else if(key.equalsIgnoreCase(ORDER_STR)) { order = root.getLong(key); } else if(key.equalsIgnoreCase(SETTINGS_STR)) { setttings = root.getJSONObject(key); } else if(key.equalsIgnoreCase(ALIASES_STR)) { aliases = root.getJSONObject(key); } else if(key.equalsIgnoreCase(MAPPINGS_STR)) { mappings = new MappingConfig(root.getJSONObject(key)); } else { notUsedMap.put(key, root.get(key)); } } if(mappings==null) { throw new Exception("not have mapping, config:" + root.toJSONString()); } }
Example 11
Source File: DataFlow.java From MicroCommunity with Apache License 2.0 | 5 votes |
public DataFlow builderByBusiness(String businessInfo) throws Exception{ try{ Business business = null; JSONObject reqInfoObj = JSONObject.parseObject(businessInfo); this.setReqJson(reqInfoObj); this.setReqData(businessInfo); this.setDataFlowId(reqInfoObj.containsKey("dataFlowId")?reqInfoObj.getString("dataFlowId"):"-1"); //this.setAppId(orderObj.getString("appId")); this.setTransactionId(reqInfoObj.getString("transactionId")); this.setOrderTypeCd(reqInfoObj.getString("orderTypeCd")); this.setRequestTime(reqInfoObj.getString("responseTime")); this.setBusinessType(reqInfoObj.getString("businessType")); //this.setReqOrders(orderObj); JSONObject businessObj = new JSONObject(); businessObj.put("bId",reqInfoObj.getString("bId")); businessObj.put("serviceCode",reqInfoObj.getString("serviceCode")); JSONArray reqBusinesses = new JSONArray(); reqBusinesses.add(businessInfo); this.setReqBusiness(reqBusinesses); JSONObject response = reqInfoObj.getJSONObject("response"); this.setCode(response.getString("code")); this.setMessage(response.getString("message")); businessObj.put("response",response); this.businesses = new ArrayList<Business>(); business = new Business().builder(businessObj); businesses.add(business); this.setCurrentBusiness(business); }catch (Exception e){ throw e; } return this; }
Example 12
Source File: RedisDataConfigSource.java From litchi with Apache License 2.0 | 5 votes |
@Override public void initialize(Litchi litchi) { this.litchi = litchi; this.blockOnConfigEmpty = litchi.currentNode().isLackConfigFileIsExit(); JSONObject config = litchi.config(Constants.Component.DATA_CONFIG); String dataSourceKey = config.getString("dataSource"); JSONObject redisConfig = config.getJSONObject(dataSourceKey); redisKey = redisConfig.getString("redisKey"); if (StringUtils.isBlank(redisKey)) { LOGGER.error("data config redis key is empty. please config it in {}", Constants.Component.DATA_CONFIG); return; } }
Example 13
Source File: DAOException.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 异常 * @return */ public String toJsonString() { JSONObject exceptionJson = JSONObject.parseObject("{\"exception\":{}"); JSONObject exceptionJsonObj = exceptionJson.getJSONObject("exception"); if (getResult() != null) exceptionJsonObj.putAll(JSONObject.parseObject(result.toString())); exceptionJsonObj.put("exceptionTrace",getMessage()); return exceptionJsonObj.toString(); }
Example 14
Source File: JeecgElasticsearchTemplate.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 根据ID获取索引数据,未查询到返回null * <p> * 查询地址:GET http://{baseUrl}/{indexName}/{typeName}/{dataId} * * @param indexName 索引名称 * @param typeName type,一个任意字符串,用于分类 * @param dataId 数据id * @return */ public JSONObject getDataById(String indexName, String typeName, String dataId) { String url = this.getBaseUrl(indexName, typeName).append("/").append(dataId).toString(); log.info("url:" + url); JSONObject result = RestUtil.get(url); boolean found = result.getBoolean("found"); if (found) { return result.getJSONObject("_source"); } else { return null; } }
Example 15
Source File: DeleteStoreInfoListener.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 根据删除信息 查出Instance表中数据 保存至business表 (状态写DEL) 方便撤单时直接更新回去 * @param dataFlowContext 数据对象 * @param business 当前业务对象 */ @Override protected void doSaveBusiness(DataFlowContext dataFlowContext, Business business) { JSONObject data = business.getDatas(); Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理"); //处理 businessStore 节点 按理这里不应该处理,程序上支持,以防真有这种业务 if(data.containsKey(StorePo.class.getSimpleName())){ JSONObject businessStore = data.getJSONObject(BusinessTypeConstant.BUSINESS_TYPE_DELETE_STORE_INFO); doBusinessStore(business,businessStore); dataFlowContext.addParamOut("storeId",businessStore.getString("storeId")); } if(data.containsKey(StoreAttrPo.class.getSimpleName())){ JSONArray businessStoreAttrs = data.getJSONArray(StoreAttrPo.class.getSimpleName()); doSaveBusinessStoreAttrs(business,businessStoreAttrs); } if(data.containsKey(StorePhotoPo.class.getSimpleName())){ JSONArray businessStorePhotos = data.getJSONArray(StorePhotoPo.class.getSimpleName()); doBusinessStorePhoto(business,businessStorePhotos); } if(data.containsKey(StoreCerdentialPo.class.getSimpleName())){ JSONArray businessStoreCerdentialses = data.getJSONArray(StoreCerdentialPo.class.getSimpleName()); doBusinessStoreCerdentials(business,businessStoreCerdentialses); } }
Example 16
Source File: FlowNode.java From rebuild with GNU General Public License v3.0 | 4 votes |
/** * @param node * @return */ public static FlowNode valueOf(JSONObject node) { return new FlowNode( node.getString("nodeId"), node.getString("type"), node.getJSONObject("data")); }
Example 17
Source File: ElasticSearchConfig.java From SuitAgent with Apache License 2.0 | 4 votes |
private static String getNodeNameOrId(int pid,int type) throws IOException { String selfNodeId = ""; String selfNodeName = ""; String netWorkHost = getNetworkHost(pid); int port = getHttpPort(pid); String url = getConnectionUrl(pid) + "/_nodes"; String responseText; try { responseText = HttpUtil.get(url).getResult(); } catch (IOException e) { log.error("访问{}异常",url,e); return ""; } JSONObject responseJSON = JSONObject.parseObject(responseText); JSONObject nodes = responseJSON.getJSONObject("nodes"); if(nodes != null){ for (Map.Entry<String, Object> entry : nodes.entrySet()) { String nodeId = entry.getKey(); JSONObject nodeInfo = (JSONObject) entry.getValue(); String nodeName = nodeInfo.getString("name"); String httpAddress = nodeInfo.getString("http_address"); if (StringUtils.isEmpty(httpAddress)) { selfNodeId = nodeId; selfNodeName = nodeName; }else { if("127.0.0.1".equals(netWorkHost) || "localhost".equals(netWorkHost)){ if(httpAddress.contains("127.0.0.1:" + port) || httpAddress.contains("localhost:" + port)){ selfNodeId = nodeId; selfNodeName = nodeName; } }else{ if(httpAddress.contains(netWorkHost + ":" + port)){ selfNodeId = nodeId; selfNodeName = nodeName; } } } } }else{ log.error("elasticSearch json结果解析失败:{}",responseText); } switch (type){ case 1: return selfNodeId; case 2: return selfNodeName; default: return ""; } }
Example 18
Source File: SysPermissionController.java From teaching with Apache License 2.0 | 4 votes |
/** * 获取菜单JSON数组 * @param jsonArray * @param metaList * @param parentJson */ private void getPermissionJsonArray(JSONArray jsonArray, List<SysPermission> metaList, JSONObject parentJson) { for (SysPermission permission : metaList) { if (permission.getMenuType() == null) { continue; } String tempPid = permission.getParentId(); JSONObject json = getPermissionJsonObject(permission); if(json==null) { continue; } if (parentJson == null && oConvertUtils.isEmpty(tempPid)) { jsonArray.add(json); if (!permission.isLeaf()) { getPermissionJsonArray(jsonArray, metaList, json); } } else if (parentJson != null && oConvertUtils.isNotEmpty(tempPid) && tempPid.equals(parentJson.getString("id"))) { // 类型( 0:一级菜单 1:子菜单 2:按钮 ) if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_2)) { JSONObject metaJson = parentJson.getJSONObject("meta"); if (metaJson.containsKey("permissionList")) { metaJson.getJSONArray("permissionList").add(json); } else { JSONArray permissionList = new JSONArray(); permissionList.add(json); metaJson.put("permissionList", permissionList); } // 类型( 0:一级菜单 1:子菜单 2:按钮 ) } else if (permission.getMenuType().equals(CommonConstant.MENU_TYPE_1) || permission.getMenuType().equals(CommonConstant.MENU_TYPE_0)) { if (parentJson.containsKey("children")) { parentJson.getJSONArray("children").add(json); } else { JSONArray children = new JSONArray(); children.add(json); parentJson.put("children", children); } if (!permission.isLeaf()) { getPermissionJsonArray(jsonArray, metaList, json); } } } } }
Example 19
Source File: AnalyzerStatusThread.java From RCT with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void handleAnalyzerStatusMessage(JSONObject message) { String analyzeIP = message.getString("ip"); if (message.get("scheduleInfo") == null || "".equals(message.getString("scheduleInfo").trim())) { return; } JSONObject scheduleInfo = message.getJSONObject("scheduleInfo"); Long scheduleID = scheduleInfo.getLong("scheduleID"); Map<String, Map<String, String>> rdbAnalyzeStatus = (Map<String, Map<String, String>>) message .get("rdbAnalyzeStatus"); List<ScheduleDetail> scheduleDetails = new ArrayList<>(); Map<String, String> newScheduleDtailsInstance = new HashMap<>(); for (Entry<String, Map<String, String>> entry : rdbAnalyzeStatus.entrySet()) { String port = entry.getKey(); if (entry.getValue() == null) { continue; } Map<String, String> analyzeInfo = entry.getValue(); AnalyzeStatus status = AnalyzeStatus.fromString(analyzeInfo.get("status")); String count = analyzeInfo.get("count"); String instance = analyzeIP + ":" + port; if (count == null || count.equals("")) { count = "0"; } ScheduleDetail s = new ScheduleDetail(scheduleID, instance, Integer.parseInt(count), true, status); scheduleDetails.add(s); newScheduleDtailsInstance.put(instance, instance); } // 将新旧信息合并 List<ScheduleDetail> oldScheduleDetails = AppCache.scheduleDetailMap.get(rdbAnalyze.getId()); List<ScheduleDetail> oldNeedScheduleDetails = new ArrayList<>(); if (oldScheduleDetails != null && oldScheduleDetails.size() > 0) { for (ScheduleDetail detail : oldScheduleDetails) { if (newScheduleDtailsInstance.containsKey(detail.getInstance())) { continue; } oldNeedScheduleDetails.add(detail); } scheduleDetails.addAll(oldNeedScheduleDetails); } AppCache.scheduleDetailMap.put(rdbAnalyze.getId(), scheduleDetails); }
Example 20
Source File: ParseHandler.java From DataLink with Apache License 2.0 | 3 votes |
/** * * Description: 异常处理 * Created on 2016-6-13 下午1:40:11 * @author 孔增([email protected]) * @param json */ public Object checkError(JSONObject json) { if(json == null) { return null; } return json.getJSONObject(ERROR_NAME); }