@Override public void add(int index, Object element) { jsonArray.add(index, element); }
/**转为JSONArray * @param tv * @return */ @NotNull public static JSONArray newJSONArray(Object obj) { JSONArray array = new JSONArray(); if (obj != null) { if (obj instanceof Collection) { array.addAll((Collection<?>) obj); } else { array.add(obj); } } return array; }
@Override public boolean add(Object e) { return jsonArray.add(e); }
@Override public void add(int index, Object element) { jsonArray.add(index, element); }
@Override public boolean add(Object e) { return jsonArray.add(e); }
@Override public CandidateDimension parse(DimensionContext context, String jsonConfig) { JSONArray jsonArray; if (jsonConfig.startsWith("[")) { jsonArray = JSON.parseArray(jsonConfig); } else { JSONObject jsonObject = JSON.parseObject(jsonConfig); jsonArray = new JSONArray(); jsonArray.add(jsonObject); } return parse(context, jsonArray); } }
/** * 处理textNode类型的节点 里面可能带着左侧空格的 都需要把空格转为空格节点 * * @param jsonNodes * @param tag * @param wholeText */ private void processMutilTextNode(JSONArray jsonNodes, String tag, String wholeText) { if (wholeText.startsWith(" ") && wholeText.length() > 1 && StrKit.notBlank(wholeText)) { String trimText = wholeText.trim(); int index = wholeText.indexOf(trimText); jsonNodes.add(processTextNode(tag, wholeText.substring(0, index))); jsonNodes.add(processTextNode(tag, wholeText.substring(index))); } else { jsonNodes.add(processTextNode(tag, wholeText)); } }
@RequestMapping("/getAllListeners") public JSONObject getAllListeners(HttpServletRequest request, HttpServletResponse response) { JSONObject result = new JSONObject(); List<RaftListener> listeners = RaftCore.getListeners(); JSONArray listenerArray = new JSONArray(); for (RaftListener listener : listeners) { if (listener instanceof VirtualClusterDomain) { listenerArray.add(((VirtualClusterDomain) listener).getName()); } } result.put("listeners", listenerArray); return result; }
private void createJsonObjectButton(JSONArray button, WechatMenu content) { JSONObject jsonObject = new JSONObject(); jsonObject.put("type", content.getType()); jsonObject.put("name", content.getText()); if ("view".equals(content.getType())) { jsonObject.put("url", content.getKeyword()); } else { jsonObject.put("key", content.getKeyword()); } button.add(jsonObject); }
@RequestMapping("/searchDom") public JSONObject searchDom(HttpServletRequest request) { JSONObject result = new JSONObject(); String namespaceId = WebUtils.optional(request, Constants.REQUEST_PARAM_NAMESPACE_ID, UtilsAndCommons.getDefaultNamespaceId()); String expr = WebUtils.required(request, "expr"); List<Domain> doms = domainsManager.searchDomains(namespaceId, ".*" + expr + ".*"); if (CollectionUtils.isEmpty(doms)) { result.put("doms", Collections.emptyList()); return result; } JSONArray domArray = new JSONArray(); for (Domain dom : doms) { domArray.add(dom.getName()); } result.put("doms", domArray); return result; }
public void extract(JSONPath path, DefaultJSONParser parser, Context context) { if (context.eval) { Object object = parser.parse(); if (deep) { List<Object> values = new ArrayList<Object>(); path.deepGetPropertyValues(object, values); context.object = values; return; } if (object instanceof JSONObject) { Collection<Object> values = ((JSONObject) object).values(); JSONArray array = new JSONArray(values.size()); for (Object value : values) { array.add(value); } context.object = array; return; } else if (object instanceof JSONArray) { context.object = object; return; } } throw new JSONException("TODO"); } }
@RequestMapping("/rt4Dom") public JSONObject rt4Dom(HttpServletRequest request) { String namespaceId = WebUtils.optional(request, Constants.REQUEST_PARAM_NAMESPACE_ID, UtilsAndCommons.getDefaultNamespaceId()); String dom = WebUtils.required(request, "dom"); VirtualClusterDomain domObj = (VirtualClusterDomain) domainsManager.getDomain(namespaceId, dom); if (domObj == null) { throw new IllegalArgumentException("request dom doesn't exist"); } JSONObject result = new JSONObject(); JSONArray clusters = new JSONArray(); for (Map.Entry<String, Cluster> entry : domObj.getClusterMap().entrySet()) { JSONObject packet = new JSONObject(); HealthCheckTask task = entry.getValue().getHealthCheckTask(); packet.put("name", entry.getKey()); packet.put("checkRTBest", task.getCheckRTBest()); packet.put("checkRTWorst", task.getCheckRTWorst()); packet.put("checkRTNormalized", task.getCheckRTNormalized()); clusters.add(packet); } result.put("clusters", clusters); return result; }
/**格式化key名称 * @param array * @return */ public static JSONArray format(final JSONArray array) { //太长查看不方便,不如debug Log.i(TAG, "format array = \n" + JSON.toJSONString(array)); if (array == null || array.isEmpty()) { Log.i(TAG, "format array == null || array.isEmpty() >> return array;"); return array; } JSONArray formatedArray = new JSONArray(); Object value; for (int i = 0; i < array.size(); i++) { value = array.get(i); if (value instanceof JSONArray) {//JSONArray,遍历来format内部项 formatedArray.add(format((JSONArray) value)); } else if (value instanceof JSONObject) {//JSONObject,往下一级提取 formatedArray.add(format((JSONObject) value)); } else {//其它Object,直接填充 formatedArray.add(value); } } //太长查看不方便,不如debug Log.i(TAG, "format return formatedArray = " + JSON.toJSONString(formatedArray)); return formatedArray; }
/** * 处理子节点 * * @param tag * @param eleJsonObj * @param needClass */ private void processChildNodes(Node node, String tag, JSONObject eleJsonObj, boolean needClass) { if (tag.toLowerCase().equals("img")) { return; } List<Node> sonNodes = node.childNodes(); JSONArray nodes = new JSONArray(); if (sonNodes.isEmpty() == false) { JSONObject soneleJsonObj = null; for (Node son : sonNodes) { soneleJsonObj = convertNodeToJsonObject(son, son.nodeName(), needClass); if (soneleJsonObj != null) { nodes.add(soneleJsonObj); } } } eleJsonObj.put("nodes", nodes); }
/**格式化key名称 * @param array * @return */ public static JSONArray format(final JSONArray array) { //太长查看不方便,不如debug Log.i(TAG, "format array = \n" + JSON.toJSONString(array)); if (array == null || array.isEmpty()) { Log.i(TAG, "format array == null || array.isEmpty() >> return array;"); return array; } JSONArray formatedArray = new JSONArray(); Object value; for (int i = 0; i < array.size(); i++) { value = array.get(i); if (value instanceof JSONArray) {//JSONArray,遍历来format内部项 formatedArray.add(format((JSONArray) value)); } else if (value instanceof JSONObject) {//JSONObject,往下一级提取 formatedArray.add(format((JSONObject) value)); } else {//其它Object,直接填充 formatedArray.add(value); } } //太长查看不方便,不如debug Log.i(TAG, "format return formatedArray = " + JSON.toJSONString(formatedArray)); return formatedArray; }
private JSONArray buildRequestLimitData(Set<String> namespaceSet) { JSONArray array = new JSONArray(); for (String namespace : namespaceSet) { array.add(new JSONObject() .fluentPut("namespace", namespace) .fluentPut("currentQps", GlobalRequestLimiter.getCurrentQps(namespace)) .fluentPut("maxAllowedQps", GlobalRequestLimiter.getMaxAllowedQps(namespace)) ); } return array; } }
@RequestMapping("/ip4Dom2") public JSONObject ip4Dom2(HttpServletRequest request) throws NacosException { String key = WebUtils.required(request, "dom"); String domName; String namespaceId; if (key.contains(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)) { namespaceId = key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0]; domName = key.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1]; } else { namespaceId = UtilsAndCommons.getDefaultNamespaceId(); domName = key; } VirtualClusterDomain dom = (VirtualClusterDomain) domainsManager.getDomain(namespaceId, domName); if (dom == null) { throw new NacosException(NacosException.NOT_FOUND, "dom: " + domName + " not found."); } List<IpAddress> ips = dom.allIPs(); JSONObject result = new JSONObject(); JSONArray ipArray = new JSONArray(); for (IpAddress ip : ips) { ipArray.add(ip.toIPAddr() + "_" + ip.isValid()); } result.put("ips", ipArray); return result; }
array.add(null);
@Override public CommandResponse<String> handle(CommandRequest request) { JSONObject info = new JSONObject(); JSONArray connectionGroups = new JSONArray(); Set<String> namespaceSet = ClusterServerConfigManager.getNamespaceSet(); for (String namespace : namespaceSet) { ConnectionGroup group = ConnectionManager.getOrCreateConnectionGroup(namespace); if (group != null) { connectionGroups.add(group); } } ServerTransportConfig transportConfig = new ServerTransportConfig() .setPort(ClusterServerConfigManager.getPort()) .setIdleSeconds(ClusterServerConfigManager.getIdleSeconds()); ServerFlowConfig flowConfig = new ServerFlowConfig() .setExceedCount(ClusterServerConfigManager.getExceedCount()) .setMaxOccupyRatio(ClusterServerConfigManager.getMaxOccupyRatio()) .setIntervalMs(ClusterServerConfigManager.getIntervalMs()) .setSampleCount(ClusterServerConfigManager.getSampleCount()) .setMaxAllowedQps(ClusterServerConfigManager.getMaxAllowedQps()); JSONArray requestLimitData = buildRequestLimitData(namespaceSet); info.fluentPut("port", ClusterServerConfigManager.getPort()) .fluentPut("connection", connectionGroups) .fluentPut("requestLimitData", requestLimitData) .fluentPut("transport", transportConfig) .fluentPut("flow", flowConfig) .fluentPut("namespaceSet", namespaceSet) .fluentPut("embedded", ClusterServerConfigManager.isEmbedded()); return CommandResponse.ofSuccess(info.toJSONString()); }