當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.put方法代碼示例

本文整理匯總了Java中net.sf.json.JSONObject.put方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.put方法的具體用法?Java JSONObject.put怎麽用?Java JSONObject.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.sf.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: caclucateMetrics

import net.sf.json.JSONObject; //導入方法依賴的package包/類
private static JSONObject caclucateMetrics(List<SampleResult> accumulatedValues, List<SampleResult> intervalValues, String label) {
    final JSONObject res = new JSONObject();

    res.put("n", accumulatedValues.size());                              // total count of samples
    res.put("name", label);                                 // label
    res.put("interval", 1);                                 // not used
    res.put("samplesNotCounted", 0);                        // not used
    res.put("assertionsNotCounted", 0);                     // not used
    res.put("failedEmbeddedResources", "[]");               // not used
    res.put("failedEmbeddedResourcesSpilloverCount", 0);    // not used
    res.put("otherErrorsCount", 0);                         // not used
    res.put("percentileHistogram", "[]");                   // not used
    res.put("percentileHistogramLatency", "[]");            // not used
    res.put("percentileHistogramBytes", "[]");              // not used
    res.put("empty", "[]");                                 // not used

    res.put("summary", generateSummary(accumulatedValues));              // summary info
    res.put("intervals", calculateIntervals(intervalValues));         // list of intervals

    addErrors(res, accumulatedValues);

    return res;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:24,代碼來源:JSONConverter.java

示例2: doPost

import net.sf.json.JSONObject; //導入方法依賴的package包/類
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	JSONObject voo = new JSONObject();
	voo.put("aircraft", "A320");
	voo.put("maxPax", 200);
	
	JSONObject piloto = new JSONObject();
	piloto.put("firstName", "John");
	piloto.put("lastName", "Doe");
	voo.put("pilot", piloto);
	
	voo.accumulate("passenger", "George");
	voo.accumulate("passenger", "Thomas");
	
	// enviar os dados no formato JSON
	PrintWriter out = response.getWriter();
	response.setContentType("text/plain");
	out.println(voo.toString(2));
}
 
開發者ID:thiagola92,項目名稱:PUC-INF1407,代碼行數:19,代碼來源:BuscaVoo.java

示例3: test_xml

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public void test_xml() throws Exception {
    XMLSerializer xmlSerializer = new XMLSerializer();
    
    JSONObject json = new JSONObject();
    json.put("id", 123);
    json.put("name", "jobs");
    json.put("flag", true);
    
    JSONArray items = new JSONArray();
    items.add("x");
    items.add(234);
    items.add(false);
    json.put("items", items);
    
    String text = xmlSerializer.write(json);
    System.out.println(text);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:JSONLibXmlTest.java

示例4: list

import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
 * @param page
 * @param rows
 * @param s_user
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/list")
public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, User s_user, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    if (page != null && rows != null) {
        PageBean pageBean = new PageBean(Integer.parseInt(page),
                Integer.parseInt(rows));
        map.put("start", pageBean.getStart());
        map.put("size", pageBean.getPageSize());
    }
    map.put("userName", StringUtil.formatLike(s_user.getUserName()));
    List<User> userList = userService.findUser(map);
    Long total = userService.getTotalUser(map);
    JSONObject result = new JSONObject();
    JSONArray jsonArray = JSONArray.fromObject(userList);
    result.put("rows", jsonArray);
    result.put("total", total);
    log.info("request: user/list , map: " + map.toString());
    ResponseUtil.write(response, result);
    return null;
}
 
開發者ID:ZHENFENG13,項目名稱:ssm-demo,代碼行數:29,代碼來源:UserController.java

示例5: extractInfo

import net.sf.json.JSONObject; //導入方法依賴的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

示例6: delete

import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
 * 刪除
 *
 * @param ids
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/delete")
public String delete(@RequestParam(value = "ids") String ids,
                     HttpServletResponse response) throws Exception {
    JSONObject result = new JSONObject();
    String[] idsStr = ids.split(",");
    for (int i = 0; i < idsStr.length; i++) {
        storeService.delStore(idsStr[i]);
    }
    result.put("success", true);
    ResponseUtil.write(response, result);
    log.info("request: store/delete , ids: " + ids);
    return null;
}
 
開發者ID:ZHENFENG13,項目名稱:ssm-demo,代碼行數:22,代碼來源:StoreController.java

示例7: popupQrImageUpdateSubmit

import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
 * 通用電腦模式,更改底部的二維碼,提交保存
 */
@RequestMapping(value = "popupQrImageUpdateSubmit")
public void popupQrImageUpdateSubmit(Model model,HttpServletRequest request,HttpServletResponse response,
		@RequestParam("qrImageFile") MultipartFile multipartFile) throws IOException{
	JSONObject json = new JSONObject();
	Site site = getSite();
	
	if(!(multipartFile.getContentType().equals("image/pjpeg") || multipartFile.getContentType().equals("image/jpeg") || multipartFile.getContentType().equals("image/png") || multipartFile.getContentType().equals("image/gif"))){
		json.put("result", "0");
		json.put("info", "請傳入jpg、png、gif格式的二維碼圖");
	}else{
		//格式轉換
		BufferedImage bufferedImage = ImageUtil.inputStreamToBufferedImage(multipartFile.getInputStream());
        BufferedImage tag = ImageUtil.formatConversion(bufferedImage);
        BufferedImage tag1 = ImageUtil.proportionZoom(tag, 400);
		
		//上傳
        AttachmentFile.put("site/"+site.getId()+"/images/qr.jpg", ImageUtil.bufferedImageToInputStream(tag1, "jpg"));
		
		AliyunLog.addActionLog(getSiteId(), "通用電腦模式,更改底部的二維碼,提交保存");
		
		json.put("result", "1");
	}
	
	response.setCharacterEncoding("UTF-8");  
    response.setContentType("application/json; charset=utf-8");  
    PrintWriter out = null;  
    try {  
        out = response.getWriter();  
        out.append(json.toString());
    } catch (IOException e) {  
        e.printStackTrace();  
    } finally {  
        if (out != null) {  
            out.close();  
        }  
    }  
}
 
開發者ID:xnx3,項目名稱:wangmarket,代碼行數:41,代碼來源:SiteController.java

示例8: testFromJSON

import net.sf.json.JSONObject; //導入方法依賴的package包/類
@org.junit.Test
public void testFromJSON() throws Exception {
    StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
    BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport());
    JSONObject object = new JSONObject();
    object.put("id", "projectId");
    object.put("name", "projectName");
    Project project = Project.fromJSON(emul, object);
    assertEquals("projectId", project.getId());
    assertEquals("projectName", project.getName());
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:12,代碼來源:ProjectTest.java

示例9: getCategories

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public ArrayList<String> getCategories(){
	ArrayList<String> categories=new ArrayList<String>();
	JSONObject r=new JSONObject();
	//構造一個請求表單
	r.put("vfwebqq",credential.getVfWebQQ());
	//這裏用到了hash
	r.put("hash", credential.getHash());
	//訪問獲取好友列表的鏈接,取出分組信息
	JSONArray result=JSONObject.fromObject(JSONObject.fromObject(utils.post(URL.URL_GET_FRIEND_LIST,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result")).getJSONArray("categories");
	//取出分組的名稱
	for(int i=0;i<result.size();i++){
		categories.add(JSONObject.fromObject(result.get(i)).getString("name"));
	}
	return categories;
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:16,代碼來源:Account.java

示例10: setUp

import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    jobConfigurationService = new JobConfigurationService();
    formData = new JSONObject();
    formData.put("projectKey", "TestKey");
}
 
開發者ID:jenkinsci,項目名稱:sonar-quality-gates-plugin,代碼行數:8,代碼來源:JobConfigurationServiceTest.java

示例11: setUp

import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    globalConfigurationService = new GlobalConfigurationService();
    spyGlobalConfigurationService = spy(globalConfigurationService);
    listOfGlobalConfigData = new ArrayList<>();
    jsonObjectNotNull = new JSONObject();
    jsonObjectNotNull.put("name", "Sonar");
    jsonObjectNotNull.put("url", "http://localhost:9000");
    jsonObjectNotNull.put("account", "admin");
    jsonObjectNotNull.put("pass", "admin");
}
 
開發者ID:jenkinsci,項目名稱:sonar-quality-gates-plugin,代碼行數:13,代碼來源:GlobalConfigurationServiceTest.java

示例12: save

import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
 * 保存或修改
 *
 * @param store
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/save")
public String save(Store store, HttpServletResponse response)
        throws Exception {
    int resultTotal = 0;
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("number", store.getNumber());
    JSONObject result = new JSONObject();
    if (storeService.findStores(map).size() > 0
            || Integer.valueOf(store.getLevel()) < 1) {
        result.put("success", false);
        ResponseUtil.write(response, result);
    } else {
        if (store.getId() == null) {
            resultTotal = storeService.insertStore(store);
        } else {
            resultTotal = storeService.updStore(store);
        }
        if (resultTotal > 0) {
            result.put("success", true);
        } else {
            result.put("success", false);
        }
        ResponseUtil.write(response, result);
    }
    log.info("request: store/save , " + store.toString());
    return null;
}
 
開發者ID:ZHENFENG13,項目名稱:ssm-demo,代碼行數:36,代碼來源:StoreController.java

示例13: list

import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
 * 查找相應的數據集合
 * 
 * @param page
 * @param rows
 * @param article
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/list")
public String list(
		@RequestParam(value = "page", required = false) String page,
		@RequestParam(value = "rows", required = false) String rows,
		Article article, HttpServletResponse response) throws Exception {
	Map<String, Object> map = new HashMap<String, Object>();
	if (page != null && rows != null) {
		PageBean pageBean = new PageBean(Integer.parseInt(page),
				Integer.parseInt(rows));
		map.put("start", pageBean.getStart());
		map.put("size", pageBean.getPageSize());
	}
	if (article != null) {
		map.put("articleTitle",
				StringUtil.formatLike(article.getArticleTitle()));
	}
	List<Article> articleList = articleService.findArticle(map);
	Long total = articleService.getTotalArticle(map);
	JSONObject result = new JSONObject();
	JSONArray jsonArray = JSONArray.fromObject(articleList);
	result.put("rows", jsonArray);
	result.put("total", total);
	ResponseUtil.write(response, result);
	log.info("request: article/list , map: " + map.toString());
	return null;
}
 
開發者ID:ZHENFENG13,項目名稱:ssm-demo,代碼行數:37,代碼來源:ArticleController.java

示例14: testFlow

import net.sf.json.JSONObject; //導入方法依賴的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

示例15: testFromJSON

import net.sf.json.JSONObject; //導入方法依賴的package包/類
@org.junit.Test
public void testFromJSON() throws Exception {
    StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
    BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport());
    JSONObject object = new JSONObject();
    object.put("id", "workspaceId");
    object.put("name", "workspaceName");
    Workspace workspace = Workspace.fromJSON(emul, object);
    assertEquals("workspaceId", workspace.getId());
    assertEquals("workspaceName", workspace.getName());
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:12,代碼來源:WorkspaceTest.java


注:本文中的net.sf.json.JSONObject.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。