Java Code Examples for com.alibaba.fastjson.JSONArray#get()
The following examples show how to use
com.alibaba.fastjson.JSONArray#get() .
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: JSONUtils.java From datax-web with MIT License | 6 votes |
/** * @param jsonStr * @param changeType 0加密 or 1解密 * @return jsonStr */ public static String changeJson(String jsonStr, Integer changeType) { JSONObject json = JSONObject.parseObject(jsonStr); JSONObject job = json.getJSONObject("job"); JSONArray contents = job.getJSONArray("content"); for (int i = 0; i < contents.size(); i++) { String contentStr = contents.getString(i); Object obj = contents.get(i); if (decrypt.equals(changeType)) { //解密 ((JSONObject) obj).put("reader", change(contentStr, "reader", decrypt)); ((JSONObject) obj).put("writer", change(contentStr, "writer", decrypt)); } else if (encrypt.equals(changeType)) {//加密 ((JSONObject) obj).put("reader", change(contentStr, "reader", encrypt)); ((JSONObject) obj).put("writer", change(contentStr, "writer", encrypt)); } } job.put("content", contents); json.put("job", job); return json.toJSONString(); }
Example 2
Source File: RequestBodyDecryptWrapper.java From SuperBoot with MIT License | 6 votes |
/** * 解密JSON数组对象 * * @param secretKey 密钥 * @param jsonArray JSON数组 * @return */ public JSONArray aesJsonArray(String secretKey, JSONArray jsonArray) { for (int i = 0; i < jsonArray.size(); i++) { //判断是否为JSON对象 if (jsonArray.get(i) instanceof JSONObject) { JSONObject jsonObject = jsonArray.getJSONObject(i); //变更JSON数组对象 jsonArray.set(i, aesJsonObject(secretKey, jsonObject)); } else { //非JSON对象直接执行解密 jsonArray.set(i, aesDecrypt(secretKey, jsonArray.getString(i))); } } return jsonArray; }
Example 3
Source File: OpenRecLiveService.java From Alice-LiveMan with GNU Affero General Public License v3.0 | 6 votes |
@Override public URI getLiveVideoInfoUrl(ChannelInfo channelInfo) throws Exception { String channelName = channelInfo.getChannelUrl().replace("https://www.openrec.tv/user/", ""); URI moviesUrl = new URI(GET_MOVIES_API + "?channel_id=" + channelName + "&sort=onair_status"); String moviesJson = HttpRequestUtil.downloadUrl(moviesUrl, channelInfo != null ? channelInfo.getCookies() : null, Collections.emptyMap(), StandardCharsets.UTF_8); JSONArray movies = JSON.parseArray(moviesJson); if (!movies.isEmpty()) { JSONObject movieObj = (JSONObject) movies.get(0); Integer onAirStatus = movieObj.getInteger("onair_status"); if (onAirStatus == 1) { String videoId = movieObj.getString("id"); return new URI(GET_VIDEO_INFO_URL + videoId); } } return null; }
Example 4
Source File: NavManagerTest.java From rebuild with GNU General Public License v3.0 | 6 votes |
@Test public void testNavBuilder() throws Exception { MockHttpServletRequestBuilder builder = MockMvcRequestBuilders .get("/rebuild") .sessionAttr(WebUtils.CURRENT_USER, UserService.ADMIN_USER); HttpServletRequest request = builder.buildRequest(new MockServletContext()); JSONArray navForPortal = NavBuilder.instance.getNavPortal(request); System.out.println("testPortalNav .......... \n" + navForPortal.toJSONString()); if (!navForPortal.isEmpty()) { JSONObject firstNav = (JSONObject) navForPortal.get(0); String navHtml = NavBuilder.instance.renderNavItem(firstNav, "home"); System.out.println(navHtml); } }
Example 5
Source File: OperationLogAspect.java From redis-manager with Apache License 2.0 | 6 votes |
/** * 这里可能不是特别合理,只为实现功能 */ private Integer getOperationGroupId(Object[] args){ Object arg = args[0]; Integer operationGroupId = -1; if (arg instanceof JSONObject){ operationGroupId = (Integer)((JSONObject)arg).get("groupId"); }else{ if (arg instanceof List) { JSONArray argArray = (JSONArray)JSONObject.toJSON(arg); JSONObject jsonObject = (JSONObject)argArray.get(0); operationGroupId = (Integer)jsonObject.get("groupId"); }else { if (arg instanceof InstallationParam){ InstallationParam installationParam = (InstallationParam)arg; Cluster cluster = installationParam.getCluster(); operationGroupId = cluster.getGroupId(); }else{ JSONObject argJson = (JSONObject)JSONObject.toJSON(arg); operationGroupId = (Integer)argJson.get("groupId"); } } } return operationGroupId; }
Example 6
Source File: TableService.java From DBus with Apache License 2.0 | 6 votes |
public void importRulesByTableId(Integer tableId, String json) { JSONArray jsonArray = JSONArray.parseArray(json); for (int i = 0; i < jsonArray.size(); i++) { JSONObject groupRules = (JSONObject) jsonArray.get(i); DataTableRuleGroup dataTableRuleGroup = new DataTableRuleGroup(); dataTableRuleGroup.setTableId(tableId); dataTableRuleGroup.setGroupName(groupRules.getString("groupName")); dataTableRuleGroup.setStatus("inactive"); dataTableRuleMapper.addGroup(dataTableRuleGroup); JSONArray rules = groupRules.getJSONArray("rules"); int order = 0; ArrayList<DataTableRule> dataTableRules = new ArrayList<>(); for (int j = 0; j < rules.size(); j++) { JSONObject rule = (JSONObject) rules.get(j); DataTableRule dataTableRule = new DataTableRule(); dataTableRule.setGroupId(dataTableRuleGroup.getId()); dataTableRule.setOrderId(order); dataTableRule.setRuleTypeName(rule.getString("ruleTypeName")); dataTableRule.setRuleGrammar(rule.getString("ruleGrammar")); dataTableRules.add(dataTableRule); order++; } dataTableRuleMapper.saveAllRules(dataTableRules); } }
Example 7
Source File: ZkHelper.java From sofa-dashboard with Apache License 2.0 | 5 votes |
private URL[] getUrls(String key, JSONObject json) throws MalformedURLException { String classPath = FastJsonUtils.getString(json, key); JSONArray urls = JSONArray.parseArray(classPath); URL[] data = new URL[urls.size()]; for (int i = 0; i < urls.size(); i++) { Object object = urls.get(i); data[i] = new URL(object == null ? "" : (String) object); } return data; }
Example 8
Source File: DetailListActivity.java From TVSample with Apache License 2.0 | 5 votes |
private void parseJson(String content) { JSONObject jason = JSONObject.parseObject(content); JSONArray data = jason.getJSONArray("items"); int totalCount = Integer.parseInt(jason.getString("count")); mDetailInfoList.clear(); for (int i = 0; i < data.size(); i++) { DetailInfo info = new DetailInfo(); JSONObject jsonObj = (JSONObject) data.get(i); String infotext = jsonObj.getString("infotext"); String url = jsonObj.getString("poster"); String title = jsonObj.getString("title"); info.setPoster(url); info.setInfotext(infotext); info.setTitle(title); mDetailInfoList.add(info); Log.d(TAG, "parseJson mDetailInfoList " + mDetailInfoList.size()); } for (int j = 0; j < mDetailInfoList.size(); j++) { Log.d(TAG, "parseJson mDetailInfoList : " + j + "content : " + mDetailInfoList.get(j).toString()); } runOnUiThread(new Runnable() { @Override public void run() { Log.d(TAG, ">> performData"); mOnDataFinishedListener.onPerformData(); } }); }
Example 9
Source File: NativeInvokeHelper.java From weex-uikit with MIT License | 5 votes |
private Object[] prepareArguments(Type[] paramClazzs, JSONArray args) throws Exception { Object[] params = new Object[paramClazzs.length]; Object value; Type paramClazz; for (int i = 0; i < paramClazzs.length; i++) { paramClazz = paramClazzs[i]; if(i>=args.size()){ if(!paramClazz.getClass().isPrimitive()) { params[i] = null; continue; }else { throw new Exception("[prepareArguments] method argument list not match."); } } value = args.get(i); if (paramClazz == JSONObject.class) { params[i] = value; } else if(JSCallback.class == paramClazz){ if(value instanceof String){ params[i] = new SimpleJSCallback(mInstanceId,(String)value); }else{ throw new Exception("Parameter type not match."); } } else { params[i] = WXReflectionUtils.parseArgument(paramClazz,value); } } return params; }
Example 10
Source File: NativeInvokeHelper.java From ucar-weex-core with Apache License 2.0 | 5 votes |
private Object[] prepareArguments(Type[] paramClazzs, JSONArray args) throws Exception { Object[] params = new Object[paramClazzs.length]; Object value; Type paramClazz; for (int i = 0; i < paramClazzs.length; i++) { paramClazz = paramClazzs[i]; if(i>=args.size()){ if(!paramClazz.getClass().isPrimitive()) { params[i] = null; continue; }else { throw new Exception("[prepareArguments] method argument list not match."); } } value = args.get(i); if (paramClazz == JSONObject.class) { params[i] = value; } else if(JSCallback.class == paramClazz){ if(value instanceof String){ params[i] = new SimpleJSCallback(mInstanceId,(String)value); }else{ throw new Exception("Parameter type not match."); } } else { params[i] = WXReflectionUtils.parseArgument(paramClazz,value); } } return params; }
Example 11
Source File: JarManagerService.java From DBus with Apache License 2.0 | 5 votes |
private ArrayList<String> getStormSupervisors() { ArrayList<String> list = new ArrayList<>(); try { JSONArray supervisors = JSONObject.parseObject(stormTopoHelper.supervisorSummary()).getJSONArray("supervisors"); for (int i = 0; i < supervisors.size(); i++) { JSONObject supervisor = (JSONObject) supervisors.get(i); list.add(supervisor.getString("host")); } } catch (Exception e) { logger.error(e.getMessage(), e); } return list; }
Example 12
Source File: FlattenJsonArrayRule.java From DBus with Apache License 2.0 | 5 votes |
private static List<String> flattenArray(String wkVal) { List<String> rows = new ArrayList<>(); if (StringUtils.isNoneEmpty(wkVal)) { JSONArray jsonArray = JSON.parseArray(wkVal); for (int i = 0; i < jsonArray.size(); i++) { Object item = jsonArray.get(i); if (item != null) { rows.add(jsonArray.get(i).toString()); } else { rows.add(StringUtils.EMPTY); } } } return rows; }
Example 13
Source File: Remote.java From jingtum-lib-java with MIT License | 5 votes |
public List formatArgs(JSONArray args) { List list = new ArrayList(); if (args != null) { for (int i = 0; i < args.size(); i++) { JSONObject jo = (JSONObject)args.get(i); list.add(hexToString(JSONObject.parseObject(jo.get("Arg").toString()).get("Parameter").toString())); } } return list; }
Example 14
Source File: DatabaseConnectController.java From incubator-iotdb with Apache License 2.0 | 5 votes |
/** * convert query result data to JSON format. * * @param request http request * @param response http response * @return data in JSON format */ @RequestMapping(value = "/query") @ResponseBody public String query(HttpServletRequest request, HttpServletResponse response) { String targetStr = "target"; response.setStatus(200); try { JSONObject jsonObject = getRequestBodyJson(request); Pair<ZonedDateTime, ZonedDateTime> timeRange = getTimeFromAndTo(jsonObject); JSONArray array = (JSONArray) jsonObject.get("targets"); // [] JSONArray result = new JSONArray(); for (int i = 0; i < array.size(); i++) { JSONObject object = (JSONObject) array.get(i); // {} if (!object.containsKey(targetStr)) { return "[]"; } String target = (String) object.get(targetStr); String type = getJsonType(jsonObject); JSONObject obj = new JSONObject(); obj.put("target", target); if (type.equals("table")) { setJsonTable(obj, target, timeRange); } else if (type.equals("timeserie")) { setJsonTimeseries(obj, target, timeRange); } result.add(i, obj); } logger.info("query finished"); return result.toString(); } catch (Exception e) { logger.error("/query failed", e); } return null; }
Example 15
Source File: FlattenJsonArrayRule.java From DBus with Apache License 2.0 | 4 votes |
private static List<String> flattenJsonArray(String wkVal, String path) { List<String> rows = new ArrayList<>(); JSONObject json = JSONObject.parseObject(wkVal); String parentPath = StringUtils.substringBeforeLast(path, "."); String currentPath = StringUtils.substringAfterLast(path, "."); if (json.containsKey(path)) { parentPath = StringUtils.EMPTY; currentPath = path; } Object currentJsonObj = JSONPath.read(wkVal, path); Object parentJsonObj = null; if (StringUtils.isBlank(parentPath)) { parentJsonObj = json; } else { parentJsonObj = JSONPath.read(wkVal, parentPath); } if (currentJsonObj instanceof JSONArray) { JSONArray retJsonArray = new JSONArray(); JSONArray currentJsonArray = (JSONArray) currentJsonObj; for (int i = 0; i < currentJsonArray.size(); i++) { JSONObject jsonItemWk = new JSONObject(); if (parentJsonObj instanceof JSONObject) { jsonItemWk = JSONObject.parseObject(((JSONObject) parentJsonObj).toJSONString()); jsonItemWk.remove(currentPath); } jsonItemWk.put(currentPath, currentJsonArray.get(i)); retJsonArray.add(jsonItemWk); } if (json.containsKey(path)) { for (int i = 0; i < retJsonArray.size(); i++) { JSONObject item = (JSONObject) retJsonArray.get(i); rows.add(item.toJSONString()); } } else { JSONPath.set(json, parentPath, retJsonArray); rows.add(json.toJSONString()); } } return rows; }
Example 16
Source File: HttpUtilTest.java From rainbow with Apache License 2.0 | 4 votes |
@Test public void HttpGetFilterTest() { SqlParser parser = new SqlParser(); Query q = null; Object o = new Object(); JSONArray jsonArray = null; int num = 0, cou = 0; while (true) { o = HttpUtil.HttpGet(Settings.PRESTO_QUERY); jsonArray = JSON.parseArray(o.toString()); String queryId = null; String query = null; for (int i = count; i < jsonArray.size(); i++) { System.out.println("Loop Times: " + num); JSONObject jsonObject = (JSONObject) jsonArray.get(i); if (jsonObject.size() == 8) { queryId = jsonObject.get("queryId").toString(); query = jsonObject.get("query").toString(); // System.out.println(queryId + "\t" + i + "\t" + query); // Parser try { q = (Query) parser.createStatement(query); } catch (Exception e) { ExceptionHandler.Instance().log(ExceptionType.ERROR, "query error", e); } // System.out.println(q.toString()); QuerySpecification queryBody = (QuerySpecification) q.getQueryBody(); // get columns List<SelectItem> selectItemList = queryBody.getSelect().getSelectItems(); for (SelectItem column : selectItemList) { System.out.println(column.toString()); } // tableName Table t = (Table) queryBody.getFrom().get(); System.out.println(t.getName()); if (t.getName().equals("text")) { System.out.println("Text visit: " + cou++); } } } // update count count = jsonArray.size(); num++; o = new Object(); } }
Example 17
Source File: FastJsonProvider.java From JsonSurfer with MIT License | 4 votes |
@Override public Object resolve(JSONArray array, int index) { return array.get(index); }
Example 18
Source File: ReliableTaildirEventReader.java From uavstack with Apache License 2.0 | 4 votes |
public void loadPositions(String json) { if (StringHelper.isEmpty(json)) { return; } Long inode = 0L, pos = 0L, number = 0L; String file = ""; JSONArray positionRecords = JSONArray.parseArray(json); for (int i = 0; i < positionRecords.size(); i++) { JSONObject positionObject = (JSONObject) positionRecords.get(i); inode = positionObject.getLong("inode"); pos = positionObject.getLong("pos"); file = positionObject.getString("file"); Long currentInode = 0L; try { currentInode = getInode(new File(file)); } catch (IOException e1) { log.err(this, "TailFile updatePos FAILED,getInode Fail.", e1); } if (!currentInode.equals(inode)) { maybeReloadMap.remove(inode); } else { // add line number number = positionObject.getLongValue("num"); for (Object v : Arrays.asList(inode, pos, file)) { Preconditions.checkNotNull(v, "Detected missing value in position file. " + "inode: " + inode + ", pos: " + pos + ", path: " + file); } TailFile tf = tailFiles.get(inode); try { if (tf != null && tf.updatePos(file, inode, pos, number)) { tailFiles.put(inode, tf); } else { // add old tail file into memory maybeReloadMap.put(inode, new Long[] { pos, number }); if (log.isDebugEnable()) { log.debug(this, "add old&inInterrupt file: " + file + ", inode: " + inode + ", pos: " + pos); } } } catch (IOException e) { log.err(this, "TailFile updatePos FAILED.", e); } } } }
Example 19
Source File: InfluxHeartbeatDaoImpl.java From sds with Apache License 2.0 | 4 votes |
@Override public List<HeartbeatDO> queryHeartbeatList(String appGroupName, String appName, String point, Date startTime, Date endTime) { List<HeartbeatDO> result = Lists.newArrayList(); if (StringUtils.isBlank(appGroupName) || StringUtils.isBlank(appName) || StringUtils.isBlank(point) || startTime == null || endTime == null) { return null; } /** * 构建influxdb的查询字符串 */ String queryStr = buildQueryString(appGroupName, appName, point, startTime, endTime); MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("q", queryStr); ResponseEntity<String> exchange = restTemplate.exchange(queryUrl, HttpMethod.POST, new HttpEntity<>(params, null), String.class); if (!exchange.getStatusCode().is2xxSuccessful() || StringUtils.isBlank(exchange.getBody())) { return null; } // { // "results": [{ // "statement_id": 0, // "series": [{ // "name": "heartbeat", // "columns": ["time", "appGroupName", "appName", "concurrentNum", "downgradeNum", "exceptionNum", // "ip", "point", "timeoutNum", "visitNum"], // "values": [ // ["2019-09-15T08:45:00.844Z", "htw", "htw-order", 15, 10, 99, "10.2.2.9", "visitPoint", // 23, 100000], // ["2019-09-15T08:45:21.959Z", "htw", "htw-order", 15, 10, 99, "10.2.2.9", "visitPoint", // 23, 100000] // ] // } // ] // }] // } /** * todo 这块代码后续需要优化 manzhizhen */ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(INFLUXDB_DATE_FORMAT); JSONObject responseJsonObject = JSONObject.parseObject(exchange.getBody()); JSONArray responseResultsJsonArray = responseJsonObject.getJSONArray("results"); JSONObject resultJsonObject = (JSONObject) responseResultsJsonArray.get(0); JSONArray seriesJsonArray = resultJsonObject.getJSONArray("series"); JSONObject heartbeatJsonObject = (JSONObject) seriesJsonArray.get(0); JSONArray columnsJsonArray = heartbeatJsonObject.getJSONArray("columns"); JSONArray valuesJsonArray = heartbeatJsonObject.getJSONArray("values"); List<Object> conlumsList = columnsJsonArray.toJavaList(Object.class); List<Object> valuesList = valuesJsonArray.toJavaList(Object.class); Map<String, Object> map = Maps.newHashMap(); for (int i = 0; i < valuesList.size(); i++) { for (int j = 0; j < conlumsList.size(); j++) { map.put(conlumsList.get(j).toString(), ((List) valuesList.get(i)).get(j)); } HeartbeatDO heartbeatDO = new HeartbeatDO(); try { heartbeatDO.setAppGroupName(map.get("appGroupName").toString()); heartbeatDO.setAppName(map.get("appName").toString()); heartbeatDO.setPoint(map.get("point").toString()); heartbeatDO.setDowngradeNum(Long.valueOf(map.get("downgradeNum").toString())); heartbeatDO.setVisitNum(Long.valueOf(map.get("visitNum").toString())); heartbeatDO.setExceptionNum(Long.valueOf(map.get("exceptionNum").toString())); heartbeatDO.setTimeoutNum(Long.valueOf(map.get("timeoutNum").toString())); heartbeatDO.setMaxConcurrentNum(Integer.valueOf(map.get("concurrentNum").toString())); heartbeatDO.setStatisticsCycleTime(simpleDateFormat.parse(map.get("time").toString())); result.add(heartbeatDO); } catch (Exception e) { logger.warn("InfluxHeartbeatDaoImpl#queryHeartbeatList 心跳数据转换异常:" + JSON.toJSONString(map), e); } } return result; }
Example 20
Source File: DatabaseConnectController.java From incubator-iotdb with Apache License 2.0 | 2 votes |
/** * get JSON type of input JSON object. * * @param jsonObject JSON Object * @return type (string) * @throws JSONException JSONException */ public String getJsonType(JSONObject jsonObject) throws JSONException { JSONArray array = (JSONArray) jsonObject.get("targets"); // [] JSONObject object = (JSONObject) array.get(0); // {} return (String) object.get("type"); }