com.alibaba.fastjson.JSONObject#getJSONObject ( )源码实例Demo

下面列出了com.alibaba.fastjson.JSONObject#getJSONObject ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: chain33-sdk-java   文件: RpcClient.java
/**
 * @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;
}
 
源代码2 项目: MicroCommunity   文件: SaveStoreInfoListener.java
/**
 * 保存商户属性信息
 *
 * @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);
    }
}
 
源代码3 项目: chain33-sdk-java   文件: RpcClient.java
/**
 * @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;
}
 
源代码4 项目: DBus   文件: DBusRouterKafkaWriteBolt.java
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);
}
 
源代码5 项目: chain33-sdk-java   文件: RpcClient.java
/**
 * @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;
}
 
源代码6 项目: MicroCommunity   文件: DeleteStoreInfoListener.java
/**
 * 根据删除信息 查出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);
    }
}
 
源代码7 项目: MicroCommunity   文件: DAOException.java
/**
 * 异常
 * @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();
}
 
源代码8 项目: JustAuth   文件: AuthMiRequest.java
@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;
}
 
源代码9 项目: weixin4j   文件: TagsComponent.java
/**
 * 创建标签
 *
 * <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;
}
 
源代码10 项目: DBus   文件: FullPullService.java
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;
}
 
源代码11 项目: MicroCommunity   文件: FilterException.java
/**
 * 异常
 * @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();
}
 
源代码12 项目: ES-Fastloader   文件: TemplateConfig.java
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());
    }
}
 
源代码13 项目: MicroCommunity   文件: DataFlow.java
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;
}
 
源代码14 项目: litchi   文件: RedisDataConfigSource.java
@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;
	}
}
 
源代码15 项目: jeecg-cloud   文件: JeecgElasticsearchTemplate.java
/**
 * 根据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;
    }
}
 
源代码16 项目: SuitAgent   文件: ElasticSearchConfig.java
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 "";
    }
}
 
源代码17 项目: RCT   文件: AnalyzerStatusThread.java
@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);
}
 
源代码18 项目: rebuild   文件: FlowNode.java
/**
 * @param node
 * @return
 */
public static FlowNode valueOf(JSONObject node) {
	return new FlowNode(
			node.getString("nodeId"), node.getString("type"), node.getJSONObject("data"));
}
 
源代码19 项目: teaching   文件: SysPermissionController.java
/**
  *  获取菜单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);
				}
			}
		}

	}
}
 
源代码20 项目: DataLink   文件: ParseHandler.java
/**
 * 
 * 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);

}