Java Code Examples for com.alibaba.fastjson.JSONArray#parseArray()
The following examples show how to use
com.alibaba.fastjson.JSONArray#parseArray() .
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: ModifyClusterParamFlowRulesCommandHandler.java From Sentinel with Apache License 2.0 | 6 votes |
@Override public CommandResponse<String> handle(CommandRequest request) { String namespace = request.getParam("namespace"); if (StringUtil.isEmpty(namespace)) { return CommandResponse.ofFailure(new IllegalArgumentException("empty namespace")); } String data = request.getParam("data"); if (StringUtil.isBlank(data)) { return CommandResponse.ofFailure(new IllegalArgumentException("empty data")); } try { data = URLDecoder.decode(data, "UTF-8"); RecordLog.info("Receiving cluster param rules for namespace <{}> from command handler: {}", namespace, data); List<ParamFlowRule> flowRules = JSONArray.parseArray(data, ParamFlowRule.class); ClusterParamFlowRuleManager.loadRules(namespace, flowRules); return CommandResponse.ofSuccess(SUCCESS); } catch (Exception e) { RecordLog.warn("[ModifyClusterParamFlowRulesCommandHandler] Decode cluster param rules error", e); return CommandResponse.ofFailure(e, "decode cluster param rules error"); } }
Example 2
Source File: HttpTestBlock001.java From gsc-core with GNU Lesser General Public License v3.0 | 6 votes |
/** * constructor. */ @Test(enabled = true, description = "get chain parameter by http") public void get11ChainParameter() { response = HttpMethed.getChainParameter(httpnode); responseContent = HttpMethed.parseResponseContent(response); HttpMethed.printJsonContent(responseContent); JSONArray jsonArray = JSONArray.parseArray(responseContent.get("chainParameter").toString()); Assert.assertTrue(jsonArray.size() >= 26); Boolean exsistDelegated = false; for (int i = 0; i < jsonArray.size(); i++) { if (jsonArray.getJSONObject(i).getString("key").equals("getAllowDelegateResource")) { exsistDelegated = true; Assert.assertTrue(jsonArray.getJSONObject(i).getString("value").equals("1")); } } Assert.assertTrue(exsistDelegated); }
Example 3
Source File: ColaTestModelStore.java From COLA with GNU Lesser General Public License v2.1 | 6 votes |
public List<ColaTestModel> load(){ List<ColaTestModel> models = null; try { RandomAccessFile rf = new RandomAccessFile(file, "r"); String line; StringBuilder sb = new StringBuilder(); while((line = rf.readLine()) != null){ line = line.trim(); if(StringUtils.isBlank(line)){ continue; } if(line.startsWith(Constants.NOTE_SYMBOL)){ continue; } sb.append(line); } JSONArray array = JSONArray.parseArray(sb.toString()); models = resolveColatestModel(array); rf.close(); } catch (Exception e) { throw new RuntimeException(e); } return models; }
Example 4
Source File: HttpTestProposal001.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * * constructor. * */ @Test(enabled = true, description = "List proposals by http") public void test2ListProposals() { response = HttpMethed.listProposals(httpnode); responseContent = HttpMethed.parseResponseContent(response); HttpMethed.printJsonContent(responseContent); JSONArray jsonArray = JSONArray.parseArray(responseContent.getString("proposals")); Assert.assertTrue(jsonArray.size() >= 1); proposalId = jsonArray.size(); }
Example 5
Source File: HttpTestAsset001.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * * constructor. * */ @Test(enabled = true, description = "Get paginated asset issue list from confirmed by http") public void test12GetPaginatedAssetissueListFromConfirmed() { response = HttpMethed.getPaginatedAssetissueListFromConfirmed(httpConfirmednode, 0, 1); responseContent = HttpMethed.parseResponseContent(response); HttpMethed.printJsonContent(responseContent); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); JSONArray jsonArray = JSONArray.parseArray(responseContent.getString("assetIssue")); Assert.assertTrue(jsonArray.size() == 1); }
Example 6
Source File: IndexControl.java From Jpom with MIT License | 5 votes |
@RequestMapping(value = "menus_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public String menusData() { NodeModel nodeModel = tryGetNode(); UserModel userModel = getUserModel(); // 菜单 InputStream inputStream; String secondary; if (nodeModel == null) { inputStream = ResourceUtil.getStream("classpath:/menus/index.json"); secondary = ""; } else { inputStream = ResourceUtil.getStream("classpath:/menus/node-index.json"); secondary = "node/"; } String json = IoUtil.read(inputStream, CharsetUtil.CHARSET_UTF_8); JSONArray jsonArray = JSONArray.parseArray(json); List<Object> collect1 = jsonArray.stream().filter(o -> { JSONObject jsonObject = (JSONObject) o; if (!testMenus(jsonObject, userModel, secondary)) { return false; } JSONArray childs = jsonObject.getJSONArray("childs"); if (childs != null) { List<Object> collect = childs.stream().filter(o1 -> { JSONObject jsonObject1 = (JSONObject) o1; return testMenus(jsonObject1, userModel, secondary); }).collect(Collectors.toList()); if (collect.isEmpty()) { return false; } jsonObject.put("childs", collect); } return true; }).collect(Collectors.toList()); return JsonMessage.getString(200, "", collect1); }
Example 7
Source File: ZkHelper.java From sofa-dashboard with Apache License 2.0 | 5 votes |
private Set<String> parseBizStateByKey(String key, JSONObject json) { String val = FastJsonUtils.getString(json, key); JSONArray urls = JSONArray.parseArray(val); Set<String> data = new HashSet<>(); for (int i = 0; i < urls.size(); i++) { JSONObject jsonObject = urls.getJSONObject(i); data.add(jsonObject.toString()); } return data; }
Example 8
Source File: ResultSetUtils.java From scaffold-cloud with MIT License | 5 votes |
public static <T> List<T> convertToList(ResultSet rs, Class<T> t) throws SQLException{ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); ResultSetMetaData md = (ResultSetMetaData) rs.getMetaData(); int columnCount = md.getColumnCount(); while (rs.next()) { Map<String, Object> rowData = new HashMap<String, Object>(); for (int i = 1; i <= columnCount; i++) { rowData.put(md.getColumnName(i), rs.getObject(i)); } list.add(rowData); } List<T> resultList = JSONArray.parseArray(JSONObject.toJSONString(list),t); return resultList; }
Example 9
Source File: WxCrawler.java From wx-crawl with Apache License 2.0 | 5 votes |
private List<ArticleSummaryObj> parseArticleListByPage(Page page) throws Exception { int startIndex = page.html().indexOf(WxCrawlerConstant.ArticleList.ARTICLE_LIST_KEY) + WxCrawlerConstant.ArticleList.ARTICLE_LIST_KEY.length(); int endIndex = page.html().indexOf(WxCrawlerConstant.ArticleList.ARTICLE_LIST_SUFFIX); String jsonStr = page.html().substring(startIndex, endIndex).trim(); jsonStr = jsonStr.substring(0,jsonStr.length()-1); JSONObject json = JSONObject.parseObject(jsonStr); return JSONArray.parseArray(json.getString("list"), ArticleSummaryObj.class); }
Example 10
Source File: HttpTestAsset001.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * * constructor. * */ @Test(enabled = true, description = "Get paginated asset issue list by http") public void test11GetPaginatedAssetissueList() { response = HttpMethed.getPaginatedAssetissueList(httpnode, 0, 1); responseContent = HttpMethed.parseResponseContent(response); HttpMethed.printJsonContent(responseContent); Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); JSONArray jsonArray = JSONArray.parseArray(responseContent.getString("assetIssue")); Assert.assertTrue(jsonArray.size() == 1); }
Example 11
Source File: TableService.java From DBus with Apache License 2.0 | 5 votes |
public void saveAllRules(Map<String, Object> map) { DataTableRuleGroup group = new DataTableRuleGroup(); group.setId(Integer.parseInt(map.get("groupId").toString())); dataTableRuleMapper.updateRuleGroup(group); dataTableRuleMapper.deleteRules(Integer.parseInt(map.get("groupId").toString())); String listTxt = map.get("rules").toString(); List<DataTableRule> list = JSONArray.parseArray(listTxt, DataTableRule.class); dataTableRuleMapper.saveAllRules(list); }
Example 12
Source File: UserService.java From Aooms with Apache License 2.0 | 5 votes |
private void addRoles(String userId){ String roleIds = getParaString("roleIds"); if(StrUtil.isNotBlank(roleIds)){ JSONArray ids = JSONArray.parseArray(roleIds); ids.forEach(id -> { Record record = Record.empty(); record.set(AoomsVar.ID,IDGenerator.getStringValue()); record.set("user_id",userId); record.set("role_id",id); record.set("create_time",DateUtil.now()); db.insert("aooms_rbac_userrole", record); }); } }
Example 13
Source File: RabbitMQPlugin.java From SuitAgent with Apache License 2.0 | 4 votes |
/** * 所有的队列监控数据 * @param rabbitMQ * @return */ private List<DetectResult.Metric> allQueueData(RabbitMQ rabbitMQ) { List<DetectResult.Metric> result = new ArrayList<>(); String apiBody = getAPIResult(rabbitMQ,"api/queues"); if (apiBody != null){ if (apiBody.trim().equals("[]")){ log.info("当前RabbitMQ({}:{})无队列数据",rabbitMQ.getIp(),rabbitMQ.getPort()); }else { JSONArray jsonArray = JSONArray.parseArray(apiBody); //队列数 result.add(new DetectResult.Metric("queues_count",String.valueOf(jsonArray.size()),CounterType.GAUGE,"")); long consumersCountTotal = 0; for (Object o : jsonArray) { JSONObject jsonObject = (JSONObject) o; String queueName = jsonObject.getString("name"); String vHost = jsonObject.getString("vhost"); if (queueName == null || vHost == null) { continue; } String tag = String.format("queue=%s,vhost=%s",queueName,vHost); consumersCountTotal += jsonObject.getLong("consumers"); //队列消费者接收新消息的时间的比例 utilForParsingJSON(result,"queues_consumer_utilisation","consumer_utilisation",jsonObject,CounterType.GAUGE,tag); //队列中的消息总数 utilForParsingJSON(result,"queues_messages","messages",jsonObject,CounterType.GAUGE,tag); //发送给客户端单但至今还未被确认的消息数量 utilForParsingJSON(result,"queues_messages_unacknowledged","messages_unacknowledged",jsonObject,CounterType.GAUGE,tag); //每秒发送给客户端但至今还未被确认的消息数量 utilForParsingJSON(result,"queues_messages_unacknowledged_rate","messages_unacknowledged_details->rate",jsonObject,CounterType.GAUGE,tag); //准备发送给客户端的数量 utilForParsingJSON(result,"queues_messages_ready","messages_ready",jsonObject,CounterType.GAUGE,tag); //每秒准备发送给客户端的数量 utilForParsingJSON(result,"queues_messages_ready_rate","messages_ready_details->rate",jsonObject,CounterType.GAUGE,tag); //发布的消息数量 utilForParsingJSON(result,"queues_messages_publish_count","message_stats->publish",jsonObject,CounterType.GAUGE,tag); //每秒发布的消息数量 utilForParsingJSON(result,"queues_messages_publish_count_rate","message_stats->publish_details->rate",jsonObject,CounterType.GAUGE,tag); //发送给客户端并确认的消息数量 utilForParsingJSON(result,"queues_messages_ack_count","message_stats->ack",jsonObject,CounterType.GAUGE,tag); //每秒发送给客户端并确认的消息数量 utilForParsingJSON(result,"queues_messages_ack_count_rate","message_stats->ack_details->rate",jsonObject,CounterType.GAUGE,tag); //消费者接收并响应的消息数量 utilForParsingJSON(result,"queues_messages_deliver_count","message_stats->deliver",jsonObject,CounterType.GAUGE,tag); //每秒消费者接收并响应的消息数量 utilForParsingJSON(result,"queues_messages_deliver_count_rate","message_stats->deliver_details->rate",jsonObject,CounterType.GAUGE,tag); } //消费者总数量 result.add(new DetectResult.Metric("queues_consumers_count_total",String.valueOf(consumersCountTotal),CounterType.GAUGE,"")); } } return result; }
Example 14
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 15
Source File: VerifyServiceImpl.java From InChat with Apache License 2.0 | 4 votes |
public JSONArray getArrayByGroupId(String groupId) { JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]"); return jsonArray; }
Example 16
Source File: SampleActivity.java From DragPointView with Apache License 2.0 | 4 votes |
private void initList() { conversationEntities = JSONArray.parseArray(ConversationEntity.TEST_JSON, ConversationEntity.class); listView.setAdapter(new ItemConversationAdapter(this, conversationEntities)); updateUnreadCount(); }
Example 17
Source File: WebServiceController.java From Cynthia with GNU General Public License v2.0 | 4 votes |
@ResponseBody @RequestMapping("/importData.do") public String importData(HttpServletRequest request , HttpServletResponse response, HttpSession httpSession) throws Exception { List<Map<String, String>> allImportDataList = new ArrayList<Map<String,String>>(); String jsonData = request.getParameter("importDatas"); JSONArray jsonArray = JSONArray.parseArray(jsonData); for (Object object : jsonArray) { JSONObject jsonObject = JSONObject.parseObject(object.toString()); Map<String, String> singleDataMap = new HashMap<String, String>(); allImportDataList.add(singleDataMap); for (String key : jsonObject.keySet()) { singleDataMap.put(key, jsonObject.getString(key)); } } if (allImportDataList.size() <= 0) { return getReturnJson("true",""); } ExcelImportControllerNew eic = new ExcelImportControllerNew(); Set<Field> allNeedFields = new HashSet<Field>(); List< Pair<String, String>> errorList = new ArrayList<Pair<String,String>>(); for(int i = 0 ; i < allImportDataList.size() ; i ++){ try { Map<String, String> exportMapData = allImportDataList.get(i); String templateIdStr = exportMapData.get("templateId"); if (CynthiaUtil.isNull(templateIdStr)) { errorList.add(new Pair<String, String>(exportMapData.get("title"), "templateId is not set!")); continue; } UUID templateId = DataAccessFactory.getInstance().createUUID(templateIdStr); Template template = das.queryTemplate(templateId); //得到表单 if (template == null) { errorList.add(new Pair<String, String>(exportMapData.get("title"), "templateId is not set!")); continue; } Flow flow = das.queryFlow(template.getFlowId()); Set<Field> allFields = eic.GetAllFields(template);//表单所有字段,除出废弃字段 Pair<String, String> saveErrorPair = eic.saveSingleData(template, flow, allNeedFields, exportMapData); if (saveErrorPair != null) { errorList.add(saveErrorPair); } } catch (Exception e) { e.printStackTrace(); } } if (errorList.size() > 0) { return getReturnJson("false", errorList); }else { return getReturnJson("true", null); } }
Example 18
Source File: EmojiConverter.java From message_interface with MIT License | 4 votes |
private boolean setup() { if (inited) { return true; } final char[] keys = {'|', '(', ')', '[', ']', '{', '}', '<', '>' , '.', '*', '\\', '^', '$', '+', '-', ',', '?', '='}; for (char key : keys) { patternKeys.add(key); } try { StringBuilder wxEmojis = new StringBuilder(); File file = ResourceUtils.getFile("classpath:config/emoji_mapping.json"); // new File("e:/emoji_mapping.json"); // String content = FileUtils.readFileToString(file, Charset.forName("utf-8")); JSONArray pairs = JSONArray.parseArray(content); for (int i = 0; i < pairs.size(); ++i) { JSONObject item = pairs.getJSONObject(i); String nim = item.getString("nim"); String wx = item.getString("wx"); // 微信的表情没有停止符,做全匹配比较好 if (i > 0) { wxEmojis.append('|'); } wxEmojis.append(escapePattern(wx)); // 存入map if (nim.startsWith("[")) { nim2Wx.put(nim, wx); } wx2Nim.put(wx, nim); } wxPattern = Pattern.compile(wxEmojis.toString(), Pattern.UNICODE_CASE); } catch (Exception e) { e.printStackTrace(); return false; } inited = true; return true; }
Example 19
Source File: FrontFeeServiceSMOImpl.java From MicroCommunity with Apache License 2.0 | 4 votes |
@Override public ResponseEntity<String> loadParkingSpaceConfigFee(IPageData pd) { validateLoadPropertyConfigFee(pd); //校验员工是否有权限操作 super.checkUserHasPrivilege(pd, restTemplate, PrivilegeCodeConstant.PRIVILEGE_PARKING_SPACE_CONFIG_FEE); JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); String communityId = paramIn.getString("communityId"); ResponseEntity responseEntity = super.getStoreInfo(pd, restTemplate); if (responseEntity.getStatusCode() != HttpStatus.OK) { return responseEntity; } Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "storeId", "根据用户ID查询商户ID失败,未包含storeId节点"); Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "storeTypeCd", "根据用户ID查询商户类型失败,未包含storeTypeCd节点"); String storeId = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeId"); String storeTypeCd = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeTypeCd"); //数据校验是否 商户是否入驻该小区 super.checkStoreEnterCommunity(pd, storeId, storeTypeCd, communityId, restTemplate); responseEntity = this.callCenterService(restTemplate, pd, "", ServiceConstant.SERVICE_API_URL + "/api/fee.queryFeeConfig" + mapToUrlParam(paramIn), HttpMethod.GET); if (responseEntity.getStatusCode() != HttpStatus.OK) { return responseEntity; } JSONArray feeConfigs = JSONArray.parseArray(responseEntity.getBody().toString()); if (feeConfigs != null && feeConfigs.size() > 1) { responseEntity = new ResponseEntity<String>("数据异常,请检查配置数据", HttpStatus.BAD_REQUEST); return responseEntity; } if (feeConfigs != null && feeConfigs.size() > 0) { responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(feeConfigs.get(0)), HttpStatus.OK); } else { responseEntity = new ResponseEntity<String>("{}", HttpStatus.OK); } return responseEntity; }
Example 20
Source File: UserRoleListController.java From Jpom with MIT License | 4 votes |
@RequestMapping(value = "save.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody @Feature(method = MethodFeature.EDIT) @OptLog(value = UserOperateLogV1.OptType.EditRole) public String save(String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "请输入角色名称") String name, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "请输入选择权限") String feature) { JSONArray jsonArray = JSONArray.parseArray(feature); RoleModel item = roleService.getItem(id); if (item == null) { item = new RoleModel(); item.setId(IdUtil.fastSimpleUUID()); } item.setName(name); List<RoleModel.RoleFeature> roleFeatures = new ArrayList<>(); jsonArray.forEach(o -> { JSONObject jsonObject = (JSONObject) o; JSONArray children = jsonObject.getJSONArray("children"); if (children == null || children.isEmpty()) { return; } String id1 = jsonObject.getString("id"); ClassFeature classFeature = ClassFeature.valueOf(id1); RoleModel.RoleFeature roleFeature = new RoleModel.RoleFeature(); roleFeature.setFeature(classFeature); roleFeatures.add(roleFeature); // List<MethodFeature> methodFeatures = new ArrayList<>(); children.forEach(o1 -> { JSONObject childrenItem = (JSONObject) o1; String id11 = childrenItem.getString("id"); id11 = id11.substring(id1.length() + 1); MethodFeature methodFeature = MethodFeature.valueOf(id11); methodFeatures.add(methodFeature); }); roleFeature.setMethodFeatures(methodFeatures); }); item.setFeatures(roleFeatures); // if (StrUtil.isNotEmpty(id)) { roleService.updateItem(item); } else { roleService.addItem(item); } return JsonMessage.getString(200, "操作成功"); }