当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.add方法代码示例

本文整理汇总了Java中net.sf.json.JSONArray.add方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.add方法的具体用法?Java JSONArray.add怎么用?Java JSONArray.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.json.JSONArray的用法示例。


在下文中一共展示了JSONArray.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractInfo

import net.sf.json.JSONArray; //导入方法依赖的package包/类
private JSONArray extractInfo(ResultSet rs) {
JSONArray jsa = new JSONArray();
ResultSetMetaData md;
try {
  md = rs.getMetaData();
  int column = md.getColumnCount();
  while (rs.next()) {
    JSONObject jsb = new JSONObject();
    for (int i = 1; i <= column; i++) {
     jsb.put(md.getColumnName(i), rs.getObject(i));
    }
    jsa.add(jsb);
  }
} catch (SQLException e) {
  e.printStackTrace();
}
return jsa;
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:19,代码来源:DBcrud.java

示例2: calculateIntervals

import net.sf.json.JSONArray; //导入方法依赖的package包/类
private static JSONArray calculateIntervals(List<SampleResult> list) {
    Map<Long, List<SampleResult>> intervals = new HashMap<>();

    for (SampleResult sample : list) {
        long time = sample.getEndTime() / 1000;
        if (!intervals.containsKey(time)) {
            intervals.put(time, new LinkedList<SampleResult>());
        }
        intervals.get(time).add(sample);
    }

    JSONArray result = new JSONArray();
    for (Long second : intervals.keySet()) {
        JSONObject intervalResult = new JSONObject();

        List<SampleResult> intervalValues = intervals.get(second);

        intervalResult.put("ts", second);
        intervalResult.put("n", intervalValues.size());
        intervalResult.put("rc", generateResponseCodec(intervalValues));
        int fails = getFails(intervalValues);
        intervalResult.put("ec", fails);
        intervalResult.put("failed", fails);
        intervalResult.put("na", getThreadsCount(intervalValues));

        final Map<String, Object> mainMetrics = getMainMetrics(intervalValues);
        int intervalSize = intervalValues.size();
        intervalResult.put("t", generateTimestamp(mainMetrics, intervalSize));
        intervalResult.put("lt", generateLatencyTime(mainMetrics, intervalSize));
        intervalResult.put("by", generateBytes(mainMetrics, intervalSize));

        result.add(intervalResult);
    }

    return result;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:37,代码来源:JSONConverter.java

示例3: testFlow

import net.sf.json.JSONArray; //导入方法依赖的package包/类
@org.junit.Test
public void testFlow() throws Exception {
    StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
    BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport());

    JSONObject result = new JSONObject();
    result.put("id", "999");
    result.put("name", "NEW_PROJECT");
    JSONObject response = new JSONObject();
    response.put("result", result);

    Workspace workspace = new Workspace(emul, "888", "workspace_name");
    emul.addEmul(response);
    Project project = workspace.createProject("NEW_PROJECT");
    assertEquals("999", project.getId());
    assertEquals("NEW_PROJECT", project.getName());

    response.clear();
    JSONArray results = new JSONArray();
    results.add(result);
    results.add(result);
    response.put("result", results);
    emul.addEmul(response);

    List<Project> projects = workspace.getProjects();
    assertEquals(2, projects.size());
    for (Project p :projects) {
        assertEquals("999", p.getId());
        assertEquals("NEW_PROJECT", p.getName());
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:32,代码来源:WorkspaceTest.java

示例4: testFlow

import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testFlow() throws Exception {
    StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
    BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport());

    JSONObject result = new JSONObject();
    result.put("id", "100");
    result.put("name", "NEW_WORKSPACE");
    JSONObject response = new JSONObject();
    response.put("result", result);

    Account account = new Account(emul, "777", "account_name");
    emul.addEmul(response);
    Workspace workspace = account.createWorkspace("NEW_WORKSPACE");
    assertEquals("100", workspace.getId());
    assertEquals("NEW_WORKSPACE", workspace.getName());

    response.clear();
    JSONArray results = new JSONArray();
    results.add(result);
    results.add(result);
    response.put("result", results);
    emul.addEmul(response);

    List<Workspace> workspaces = account.getWorkspaces();
    assertEquals(2, workspaces.size());
    for (Workspace wsp :workspaces) {
        assertEquals("100", wsp.getId());
        assertEquals("NEW_WORKSPACE", wsp.getName());
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:32,代码来源:AccountTest.java

示例5: testFlow

import net.sf.json.JSONArray; //导入方法依赖的package包/类
@org.junit.Test
public void testFlow() throws Exception {
    StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
    BlazeMeterReport report = new BlazeMeterReport();

    BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", report);

    User user = new User(emul);
    emul.addEmul(new JSONObject());
    user.ping();

    JSONObject acc = new JSONObject();
    acc.put("id", "accountId");
    acc.put("name", "accountName");
    JSONArray result = new JSONArray();
    result.add(acc);
    result.add(acc);
    JSONObject response = new JSONObject();
    response.put("result", result);
    emul.addEmul(response);

    List<Account> accounts = user.getAccounts();
    assertEquals(2, accounts.size());
    for (Account account : accounts) {
        assertEquals("accountId", account.getId());
        assertEquals("accountName", account.getName());
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:29,代码来源:UserTest.java

示例6: buildGitData

import net.sf.json.JSONArray; //导入方法依赖的package包/类
public static JSONArray buildGitData(EnvVars envVars, PrintStream printStream) {
	try {
		String gitUrl = Util.getGitRepoUrl(envVars);
       	String gitBranch = Util.getGitBranch(envVars);
       	String gitCommit = Util.getGitCommit(envVars);
       	
       	JSONObject gitInfo = new JSONObject();
       	gitInfo.put("GitURL" , gitUrl);
       	gitInfo.put("GitBranch" , gitBranch);
       	gitInfo.put("GitCommitID" , gitCommit);
       	
		JSONArray gitData = new JSONArray();
       	gitData.add(gitInfo);
		
       	return gitData;
		
	} catch (Exception e) {
		printStream.println("[IBM Cloud DevOps] Error: Failed to build Git data.");
		e.printStackTrace(printStream);
		throw e;
	}
}
 
开发者ID:IBM,项目名称:ibm-cloud-devops,代码行数:23,代码来源:MessageUtil.java

示例7: chatRecord

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * 聊天记录,跟某个人之间,一个会话的聊天记录,两个人之间的聊天记录
 * @param id 跟自己会话的那个人的id,对方的id
 */
@RequestMapping("chatRecord")
public String chatRecord(HttpServletRequest request,Model model,
		@RequestParam(value = "id", required = false , defaultValue="0") long id){
	if(id == 0){
		return error(model, "请输入要查看得对方得id编号");
	}
	User user = getUser();
	int currentTime = DateUtil.timeForUnix10();
	int startTime = currentTime - 86400*30;	//30天内有效
	try {
		AliyunLogPageUtil log = new AliyunLogPageUtil(Global.aliyunLogUtil);
		JSONArray jsonArray = log.listForJSONArray("(receiveId = "+user.getId()+" and sendId = "+id+" ) or (receiveId = "+id+" and sendId = "+user.getId()+" )", "", false, startTime, currentTime, 100, request);
		JSONArray ja = new JSONArray();	//将其倒序
		for (int i = jsonArray.size()-1; i >-1 ; --i) {
			ja.add(jsonArray.get(i));
		}
		model.addAttribute("list", ja);
	} catch (LogException e) {
		e.printStackTrace();
	}
	
	model.addAttribute("user", user);
	return "im/chatRecord";
}
 
开发者ID:xnx3,项目名称:wangmarket,代码行数:29,代码来源:ImController.java

示例8: toGetAll

import net.sf.json.JSONArray; //导入方法依赖的package包/类
private void toGetAll(HttpServletRequest request, HttpServletResponse response) throws IOException {
	String time = request.getParameter("time");
	String page = request.getParameter("page");
	int pageNum = 1;
	int size = 12;
	if (page != null && page.equals("") == false) {
		pageNum = Integer.parseInt(page);
	}
	if (time == null || time.equals("")) {
		Date date = new Date();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		time = df.format(date);
	}
	List<Signinall> list = userDao.getAll(time, pageNum, size);
	if (list == null) {
		response.getWriter().print("none");
		return;
	}
	JSONArray js = new JSONArray();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
	for (Signinall signinall : list) {
		signinall.setTime(sdf.format(signinall.getStime()));
		js.add(getJsonObj(signinall.getSid(), signinall.getUid(), signinall.getTime(), signinall.getUname(),
				signinall.getUsex(), signinall.getState(), signinall.getUclass()));
	}
	response.getWriter().print(js.toString());
}
 
开发者ID:sivanWu0222,项目名称:Registration,代码行数:28,代码来源:UserServlet.java

示例9: getDataToSend

import net.sf.json.JSONArray; //导入方法依赖的package包/类
public JSONArray getDataToSend(List<SampleResult> list) {
    JSONArray data = new JSONArray();

    SortedMap<Long, List<SampleResult>> sortedResults = sortResults(list);
    for (Long sec : sortedResults.keySet()) {
        data.add(getAggregateSecond(sec, sortedResults.get(sec)));
    }
    return data;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:10,代码来源:LoadosophiaClient.java

示例10: getLabels

import net.sf.json.JSONArray; //导入方法依赖的package包/类
public static JSONArray getLabels(List<SampleResult> accumulatedValues, List<SampleResult> intervalValues) {
    JSONArray jsonArray = new JSONArray();

    jsonArray.add(caclucateMetrics(accumulatedValues, intervalValues, SUMMARY_LABEL));

    Map<String, List<SampleResult>> sortedAccumulatedSamples = sortSamplesByLabel(accumulatedValues);
    Map<String, List<SampleResult>> sortedIntervalSamples = sortSamplesByLabel(intervalValues);

    for (String label : sortedIntervalSamples.keySet()) {
        jsonArray.add(caclucateMetrics(sortedAccumulatedSamples.get(label), sortedIntervalSamples.get(label), label));
    }

    return jsonArray;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:15,代码来源:JSONConverter.java

示例11: spiderList

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * 爬虫访问列表,列出最近7天内,最近的100条爬虫记录
 */
@RequestMapping("spiderList")
@ResponseBody
public RequestLogItemListVO spiderList(HttpServletRequest request) throws LogException{
	RequestLogItemListVO vo = new RequestLogItemListVO();
	
	//当前10位时间戳
	int currentTime = DateUtil.timeForUnix10();
	String query = "siteid="+getSiteId();
	String spider = null;
	for (int i = 0; i < spiderNameArray.length; i++) {
		if(spider == null){
			spider = spiderNameArray[i];
		}else{
			spider = spider + " or " + spiderNameArray[i];
		}
	}
	query = query + " and ("+spider+")";
	
	//当月访问量统计
	ArrayList<QueriedLog> jinriQlList = G.aliyunLogUtil.queryList(query, "", DateUtil.getDateZeroTime(currentTime - 604800), currentTime, 0, 100, true);
	
	JSONArray jsonArray = new JSONArray();	//某天访问量,pv
	for (int i = 0; i < jinriQlList.size(); i++) {
		LogItem li = jinriQlList.get(i).GetLogItem();
		JSONObject json = JSONObject.fromObject(li.ToJsonString());
		try {
			json.put("logtimeString", DateUtil.dateFormat(json.getInt("logtime"), "MM-dd HH:mm"));
		} catch (NotReturnValueException e) {
			e.printStackTrace();
		}
		
		UserAgent ua = UserAgent.parseUserAgentString(json.getString("userAgent"));
		json.put("os", ua.getOperatingSystem());
		json.put("browser", ua.getBrowser());
		if(ua.getOperatingSystem().getName().equals("Unknown")){
			String userAgent = json.getString("userAgent");
			//没有发现是哪个浏览器,那可能是爬虫
			for (int j = 0; j < spiderNameArray.length; j++) {
				if(userAgent.indexOf(spiderNameArray[j]) > -1){
					json.put("os", spiderExplainArray[j]);
				}
			}
			
			if(json.get("os") == null){
				if(userAgent.equals("Mozilla")){
					//忽略
				}else{
					System.out.println("未发现的useragent : "+json.toString());
				}
			}
		}
		
		jsonArray.add(json);
		
	}
	vo.setList(jsonArray);
	
	AliyunLog.addActionLog(getSiteId(), "获取最近7天内,最近的100条访问记录");
	
	return vo;
}
 
开发者ID:xnx3,项目名称:wangmarket,代码行数:65,代码来源:RequestLogController.java

示例12: testGetGlobalConfigsArrayWhenObject

import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testGetGlobalConfigsArrayWhenObject() {
    jsonArray = new JSONArray();
    doReturn(jsonArray).when(spyGlobalConfigurationService).createJsonArrayFromObject(JSONObject.fromObject(globalDataConfigs));
    String objectString = "{\"name\":\"Sonar\",\"url\":\"http://localhost:9000\",\"account\":\"admin\",\"password\":\"admin\"}";
    globalDataConfigs = JSONSerializer.toJSON(objectString);
    jsonArray.add(globalDataConfigs);
    assertEquals(jsonArray, spyGlobalConfigurationService.getGlobalConfigsArray(globalDataConfigs));
}
 
开发者ID:jenkinsci,项目名称:sonar-quality-gates-plugin,代码行数:10,代码来源:GlobalConfigurationServiceTest.java

示例13: toJSONArray

import net.sf.json.JSONArray; //导入方法依赖的package包/类
private JSONArray toJSONArray(Set<? extends BaseStatement> set) {
    JSONArray jsonArray = new JSONArray();
    for (BaseStatement s : set) {
        jsonArray.add(s.toJSONObject());
    }
    return jsonArray;
}
 
开发者ID:AlbieLiang,项目名称:IPCInvoker,代码行数:8,代码来源:IPCInvokeTaskProcessor.java

示例14: dayLineForCurrentMonth

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * 折线图,当月(最近30天),每天的访问情况
 */
@RequestMapping("dayLineForCurrentMonth")
@ResponseBody
public RequestLogDayLineVO dayLineForCurrentMonth(HttpServletRequest request) throws LogException{
	RequestLogDayLineVO vo = new RequestLogDayLineVO();
	
	//当前10位时间戳
	int currentTime = DateUtil.timeForUnix10();
	String query = "siteid="+getSiteId()+" | timeslice 24h | count as c";
	
	//当月访问量统计
	ArrayList<QueriedLog> jinriQlList = G.aliyunLogUtil.queryList(query, "", DateUtil.getDateZeroTime(currentTime - 2592000), currentTime, 0, 100, true);
	
	JSONArray jsonArrayDate = new JSONArray();	//天数
	JSONArray jsonArrayFangWen = new JSONArray();	//某天访问量,pv
	for (int i = 0; i < jinriQlList.size(); i++) {
		LogItem li = jinriQlList.get(i).GetLogItem();
		JSONObject json = JSONObject.fromObject(li.ToJsonString());
		try {
			jsonArrayDate.add(DateUtil.dateFormat(json.getInt("logtime"), "MM-dd"));
		} catch (NotReturnValueException e) {
			e.printStackTrace();
		}
		jsonArrayFangWen.add(json.getInt("c"));
	}
	vo.setJsonArrayFangWen(jsonArrayFangWen);
	vo.setJsonArrayDate(jsonArrayDate);
	
	AliyunLog.addActionLog(getSiteId(), "获取最近30天的访问数据统计记录");
	
	return vo;
}
 
开发者ID:xnx3,项目名称:wangmarket,代码行数:35,代码来源:RequestLogController.java

示例15: generateJSONResponse

import net.sf.json.JSONArray; //导入方法依赖的package包/类
private String generateJSONResponse(Result result) {
    JSONObject out = new JSONObject();
    out.put("input", result.getText());

    JSONObject sent = new JSONObject();
    sent.put("label", result.getSentiment());
    sent.put("score", result.getSentimentScore());
    out.put("sentiment", sent);

    JSONObject rel = new JSONObject();
    rel.put("label", result.getRelevance());
    rel.put("score", result.getRelevanceScore());
    out.put("relevance", rel);

    JSONObject asp = new JSONObject();
    asp.put("label", result.getAspect());
    asp.put("score", result.getAspectScore());
    out.put("aspect", asp);


    JSONObject aspCoarse = new JSONObject();
    aspCoarse.put("label", result.getAspectCoarse());
    aspCoarse.put("score", result.getAspectCoarseScore());
    out.put("aspect_coarse", aspCoarse);

    JSONArray targets = new JSONArray();
    for (AspectExpression a : result.getAspectExpressions()) {
        targets.add(a.getAspectExpression());
    }
    out.put("targets", targets);

    return out.toString();
}
 
开发者ID:uhh-lt,项目名称:LT-ABSA,代码行数:34,代码来源:ApplicationController.java


注:本文中的net.sf.json.JSONArray.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。