com.alibaba.fastjson.JSONArray#toJSONString ( )源码实例Demo

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

@Override
public ServiceConfigPushHistory add(ServiceConfig serviceConfig, PushResult cacheCenterPushResult) {

    List<ServiceConfigText> serviceConfigTexts = new ArrayList<>();
    ServiceConfigText serviceConfigText = new ServiceConfigText();
    serviceConfigText.setName(serviceConfig.getName());
    serviceConfigTexts.add(serviceConfigText);

    //构造推送历史记录实体
    ServiceConfigPushHistory servicePushHistory = new ServiceConfigPushHistory(
            cacheCenterPushResult.getPushId(), this.getUserId(), serviceConfig.getGrayId(),
            serviceConfig.getProject().getName(), serviceConfig.getCluster().getName(), serviceConfig.getService().getName(),
            serviceConfig.getServiceVersion().getVersion(), cacheCenterPushResult.getResult(), JSONArray.toJSONString(serviceConfigTexts),
            new Date());

    //新增
    this.servicePushHistoryMapper.insert(servicePushHistory);
    return servicePushHistory;
}
 
源代码2 项目: Cynthia   文件: QuitBugMoveController.java
/**
 * @description:get the quit users from template
 * @date:2014-5-5 下午8:35:55
 * @version:v1.0
 * @param templateIdStr
 * @param roleIdStr
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/getQuitUser.do")
public String getQuitUser(@RequestParam("templateId") String templateIdStr , @RequestParam("roleId") String roleIdStr) throws Exception {
	if (roleIdStr == null || roleIdStr.length() == 0 || templateIdStr == null || templateIdStr.length() == 0) {
		return "";
	}
	UUID roleId = DataAccessFactory.getInstance().createUUID(roleIdStr);
	
	Template template = das.queryTemplate(DataAccessFactory.getInstance().createUUID(templateIdStr));
	
	Flow flow = das.queryFlow(template.getFlowId());
	
	List<UserInfo> allQuitUserList = getAllQuitUser(template, flow, roleId);
	
	return JSONArray.toJSONString(allQuitUserList);
}
 
源代码3 项目: Cynthia   文件: BugVersionMoveController.java
/**
 * @description:get datas by template id
 * @date:2014-5-5 下午8:17:05
 * @version:v1.0
 * @param templateId
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/getTemplateDatas.do")
public String getTempalteDatas(@RequestParam("templateId") String templateId) throws Exception {
	Map<String, String> templateIdTitleMap = new DataAccessSessionMySQL().queryIdAndFieldOfTemplate(templateId, "title");
	
	List<DataVO> templateDataList = new ArrayList<DataVO>();
	for(String dataId : templateIdTitleMap.keySet())
	{
		DataVO dataVO = new DataVO();
		dataVO.setId(dataId);
		dataVO.setName(templateIdTitleMap.get(dataId));
		templateDataList.add(dataVO);
	}
	return JSONArray.toJSONString(templateDataList);
}
 
源代码4 项目: Cynthia   文件: BackRightController.java
/**
 * @Title:initUserFlowRight
 * @Type:BackRightController
 * @description:init user flow rights
 * @date:2014-5-5 下午8:04:34
 * @version:v1.0
 * @param request
 * @param httpSession
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/initUserFlowRight.do")
public String initUserFlowRight(HttpServletRequest request,HttpSession httpSession) throws Exception {
	
	Key key = (Key)httpSession.getAttribute("key");
	String userMail = key.getUsername();
	
	Map<String, String> temMap = das.queryUserTemplateRights(userMail);
	Set<String> flowSet = new HashSet<String>();
	for (String templateId : temMap.keySet()) {
		Template template = das.queryTemplate(DataAccessFactory.getInstance().createUUID(templateId));
		if (template != null) {
			flowSet.add(template.getFlowId().getValue());
		}
	}
	
	//自己创建的表单具有编辑权限
	for (Flow flow : das.queryAllFlows()) {
		if (flow != null && flow.getCreateUser() != null && flow.getCreateUser().equals(key.getUsername())) {
			flowSet.add(flow.getId().getValue());
		}
	}
	return JSONArray.toJSONString(flowSet);
}
 
源代码5 项目: rainbow   文件: RwMain.java
public void savePipelineState(Pipeline pipeline, String state) {
    String time = DateUtil.formatTime(new Date());
    State s = new State(time, state);
    Process p = searchProcessByPno(pipeline.getNo());
    if (p != null) {
        p.getPipelineState().add(s);
    } else {
        List<State> PipelineState = new ArrayList<>();
        PipelineState.add(s);
        p = new Process(pipeline.getNo(), PipelineState);
        SysConfig.ProcessList.add(p);
    }
    String processListJson = JSONArray.toJSONString(SysConfig.ProcessList);
    try {
        FileUtil.writeFile(processListJson, SysConfig.Catalog_Project + "cashe/process.txt");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
源代码6 项目: withme3.0   文件: UserServiceImplement.java
@Override
public Response getRelations(Integer userId) {
    try {
        List<User> userList = new ArrayList<>();
        User user = userRepository.findByUserId(userId);
        if (!Common.isNull(user)) {
            if (!Common.isEmpty(user.getUserRelations())) {
                String[] relation = user.getUserRelations().split(",");
                for (String friendId : relation) {
                    User user1 = userRepository.findByUserId(Integer.valueOf(friendId));
                    userList.add(user1);
                }
            }
        }
        return new Response(1, "获取好友成功", JSONArray.toJSONString(userList));
    } catch (Exception e) {
        e.printStackTrace();
        return new Response(-1, "获取好友异常", null);
    }
}
 
源代码7 项目: withme3.0   文件: UserServiceImplement.java
@Override
    public Response getUsersByUserIds(String userIds) {
        try {
            String[] users = userIds.split(",");
//            ArrayList<Integer> intIds = new ArrayList<>();
            List<AuthUser> userList = new ArrayList<>();
            for (String userId : users) {
                //TODO 优化为不使用循环
                User user = userRepository.findByUserId(Integer.valueOf(userId));
                AuthUser authUser = new AuthUser(user.getUserId(), user.getUserName(), user.getUserNickName(), Common.getCurrentTime());
                userList.add(authUser);
            }
            return new Response(1, "获取用户成功", JSONArray.toJSONString(userList));
        } catch (Exception e){
            e.printStackTrace();
            return new Response(-1, "获取用户失败", null);
        }
    }
 
@Override
    @Transactional
    public Response getOfflineMessageTo(Integer userId) {
        try {
            List<OfflineMessage> messages = offlineMessageRepository.findAllByToId(userId);

            offlineMessageRepository.deleteAllByToId(userId);
//            Response response = restTemplate.postForEntity(CONSTANT.MESSAGE_SERVICE_ADD_MESSAGES, messages, Response.class).getBody();
//            if(response.getStatus() != 1){
//                throw new Exception();
//            }

            List<OfflineGroupMessage> groupMessages = offlineGroupMessageRepository.findAllByToId(userId);
            for(OfflineGroupMessage offlineGroupMessage : groupMessages){
                messages.add(new OfflineMessage(offlineGroupMessage));
            }
            offlineMessageRepository.deleteAllByToId(userId);
            return new Response(1, "Get offline messages success", JSONArray.toJSONString(messages, SerializerFeature.UseSingleQuotes));
        } catch (Exception e) {
            e.printStackTrace();
            return new Response(-1, "Get offline messages error", null);
        }
    }
 
源代码9 项目: DevUtils   文件: FastjsonUtils.java
/**
 * JSON String 缩进处理
 * @param json JSON String
 * @return JSON String
 */
public static String toJsonIndent(final String json) {
    if (json != null) {
        try {
            // 保持 JSON 字符串次序
            Object object = JSON.parse(json, Feature.OrderedField);
            if (object instanceof JSONObject) {
                return JSONObject.toJSONString(object, true);
            } else if (object instanceof JSONArray) {
                return JSONArray.toJSONString(object, true);
            }
        } catch (Exception e) {
            JCLogUtils.eTag(TAG, e, "toJsonIndent");
        }
    }
    return null;
}
 
源代码10 项目: jeewx-boot   文件: ApiCmsController.java
/**
 * 返回栏目数据
 * @param query
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/menu", method = { RequestMethod.GET, RequestMethod.POST })
public @ResponseBody String menu(HttpServletRequest request, HttpServletResponse response) throws Exception {
	//根据MainId过滤数据
	String mainId = request.getParameter("mainId");
	String ishref = request.getParameter("ishref");
	List<CmsMenu> list = cmsMenuService.getFirstMenu(mainId, ishref);
	return JSONArray.toJSONString(list);
}
 
源代码11 项目: jpress   文件: HtmlToJson.java
/**
 * 获取转换后的JSON 数组 有多级子节点
 *
 * @return
 */
public String get() {
    if (StrKit.isBlank(html)) {
        return null;
    }
    Document document = null;
    try {
        //判断是否需要绝对路径URL
        if (needAbsUrl) {
            document = Jsoup.parseBodyFragment(html, params.getBaseUri());
        } else {
            document = Jsoup.parseBodyFragment(html);
        }
    } finally {
        if (document == null) {
            return null;
        }
    }
    //以前使用Element元素会把无标签包裹的textNode节点给抛弃,这里改为选用Node节点实现
    //Node节点可以将一段html的所有标签和无标签文本区分 都转为Node
    List<Node> nodes = document.body().childNodes();
    //如果获取的Node为空 直接返回Null不处理
    if (nodes.isEmpty()) {
        return null;
    }
    //整个HTML转为JSON其实是转为一个JSON数组传递给前端html2wxml组件模板 循环解析
    JSONArray array = new JSONArray();
    JSONObject jsonObject = null;
    String tag = null;
    for (Node node : nodes) {
        tag = node.nodeName().toLowerCase();
        jsonObject = convertNodeToJsonObject(node, tag, "pre".equals(tag));
        if (jsonObject != null) {
            array.add(jsonObject);
        }
    }
    return array.toJSONString();
}
 
源代码12 项目: txle   文件: ConfigRestApi.java
@GetMapping("/readSystemConfigCache")
public String readSystemConfigCache() {
    JSONArray jsonArray = new JSONArray();
    Map<String, String> systemConfigCache = this.consistencyCache.getSystemConfigCache();
    systemConfigCache.keySet().forEach(key -> {
        JSONObject json = new JSONObject();
        json.put(key, systemConfigCache.get(key));
        jsonArray.add(json);
    });
    return jsonArray.toJSONString();
}
 
源代码13 项目: kafka-eagle   文件: JSONFunction.java
/** Parse a JSONArray. */
public String JSONS(String jsonArray, String key) {
	JSONArray object = com.alibaba.fastjson.JSON.parseArray(jsonArray);
	JSONArray target = new JSONArray();
	for (Object tmp : object) {
		JSONObject result = (JSONObject) tmp;
		JSONObject value = new JSONObject();
		value.put(key, result.getString(key));
		target.add(value);
	}
	return target.toJSONString();
}
 
源代码14 项目: rainbow   文件: RwMain.java
private void changeState(String pno, int state) {
    for (Pipeline p : SysConfig.PipelineList) {
        if (p.getNo().equals(pno)) {
            p.setState(state);
            break;
        }
    }
    String aJson = JSONArray.toJSONString(SysConfig.PipelineList);
    try {
        FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/cashe.txt");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
源代码15 项目: withme3.0   文件: GroupServiceImplement.java
@Override
public Response findGroupByIds(String ids) {
    String[] strIds = ids.split(",");
    List<Integer> intIds = new ArrayList<>();
    for(String groupId : strIds){
        intIds.add(Integer.valueOf(groupId));
    }
    List<Groups> groups = groupRepository.findByIdIn(intIds);
    return new Response(1, "获取群组成功", JSONArray.toJSONString(groups));
}
 
源代码16 项目: kafka-eagle   文件: KafkaServiceImpl.java
/**
 * Get zookeeper cluster information.
 */
public String zkCluster(String clusterAlias) {
	String[] zks = SystemConfigUtils.getPropertyArray(clusterAlias + ".zk.list", ",");
	JSONArray targets = new JSONArray();
	int id = 1;
	for (String zk : zks) {
		JSONObject object = new JSONObject();
		object.put("id", id++);
		object.put("ip", zk.split(":")[0]);
		object.put("port", zk.split(":")[1]);
		object.put("mode", zkService.status(zk.split(":")[0], zk.split(":")[1]));
		targets.add(object);
	}
	return targets.toJSONString();
}
 
源代码17 项目: Cynthia   文件: BatchModifyController.java
/**
 * 
 * @Title:getCloseActionAndUser
 * @Type:BatchModifyController
 * @description:return the usable actions and users for batch close data
 * @date:2014-5-5 下午8:07:58
 * @version:v1.0
 * @param request
 * @param response
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping("/getCloseActionAndUser.do")
@ResponseBody
public String getCloseActionAndUser(HttpServletRequest request, HttpServletResponse response ,HttpSession session) throws Exception {
	
	String[] dataIdStrArray = request.getParameterValues("dataIds[]");
	if(dataIdStrArray == null || dataIdStrArray.length == 0){
		return "";
	}
	
	UUID[] dataIdArray = new UUID[dataIdStrArray.length];
	for(int i = 0; i < dataIdArray.length; i++){
		dataIdArray[i] = DataAccessFactory.getInstance().createUUID(dataIdStrArray[i]);
	}
	
	DataAccessSession das = DataAccessFactory.getInstance().createDataAccessSession(session.getAttribute("userName").toString(), ConfigUtil.magic);
	
	String actionsXML = DataManager.getInstance().getBatchCloseActionsXML(dataIdArray, das);
	
	if(actionsXML == null){
		return "";
	}
	
	Map<String, Set<String>> actionUserMap = new LinkedHashMap<String, Set<String>>();
	
	Document document = XMLUtil.string2Document(actionsXML, "UTF-8");
	List<Node> actionNodeList = XMLUtil.getNodes(document, "actions/action");
	for(Node actionNode : actionNodeList){
		String actionName = XMLUtil.getSingleNodeTextContent(actionNode, "name");
		actionUserMap.put(actionName, new LinkedHashSet<String>());
	}
	
	return JSONArray.toJSONString(actionUserMap);
}
 
源代码18 项目: Cynthia   文件: BugVersionMoveController.java
/**
 * @description:get tasks of template
 * @date:2014-5-5 下午8:16:31
 * @version:v1.0
 * @param oldTaskId
 * @param bugTaskFieldId
 * @return
 * @throws Exception
 */
@ResponseBody
@RequestMapping("/getTaskBugTemplate.do")
public String getTaskBugTemplate(@RequestParam("oldTaskId") String oldTaskId ,@RequestParam("bugTaskField") String bugTaskFieldId ) throws Exception {
	
	Data oldTask = das.queryData(DataAccessFactory.getInstance().createUUID(oldTaskId));
	UUID [] bugs = oldTask.getMultiReference(DataAccessFactory.getInstance().createUUID(bugTaskFieldId));
	Map<String,Template> bugTemplateMap = new HashMap<String,Template>();
	Data bugData = null;
	
	Map<UUID, Template> allTemplateMap = new HashMap<UUID, Template>();
	
	if(bugs!=null&&bugs.length>0){
		for(UUID id : bugs){
		 bugData = das.queryData(id);	
		 if(bugData!=null){
			if (allTemplateMap.get(bugData.getTemplateId()) == null) {
				allTemplateMap.put(bugData.getTemplateId(), das.queryTemplate(bugData.getTemplateId()));
			} 
			Template template = allTemplateMap.get(bugData.getTemplateId());
			if(template!=null)
				bugTemplateMap.put(template.getId().toString(), template);
		 }
		}
	}
	
	return JSONArray.toJSONString(bugTemplateMap);
}
 
源代码19 项目: Cynthia   文件: ProjectController.java
/**
 * @Title: getAllTemplate
 * @Description: 通过产品获取项目
 * @param request
 * @param response
 * @param session
 * @return
 * @throws Exception
 * @return: String
 */
@RequestMapping("/getProjects.do")
@ResponseBody
public String getProjects(HttpServletRequest request, HttpServletResponse response ,HttpSession session) throws Exception {
	Map<String, String> allProjectsMap = new HashMap<String, String>();
	String userName = (String)request.getSession().getAttribute("userName");
	String productId = request.getParameter("productId");
	allProjectsMap = ProjectInvolveManager.getInstance().getProjectMap(userName, productId);
	return JSONArray.toJSONString(allProjectsMap);
}
 
源代码20 项目: Cynthia   文件: StatisticController.java
/**
 * @description:query all statistics of user
 * @date:2014-5-5 下午8:39:58
 * @version:v1.0
 * @param request
 * @param response
 * @param session
 * @return
 * @throws Exception
 */
@RequestMapping("/queryAllStatistics.do")
@ResponseBody
public String queryAllStatistics(HttpServletRequest request, HttpServletResponse response ,HttpSession session) throws Exception {
	String userName = ((Key)session.getAttribute("key")).getUsername();
	List<TimerAction> allTimerActions = new ArrayList<TimerAction>();
	allTimerActions.addAll(Arrays.asList(das.queryStatisticByUser(userName)));
	return JSONArray.toJSONString(allTimerActions);
}