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


Java JSONArray.toString方法代碼示例

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


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

示例1: getOption

import net.sf.json.JSONArray; //導入方法依賴的package包/類
/**
 * replacement的value為String類型時,直接根據key替換,否則轉為Json》String後再替換
 * @author ack (chenzhao)  @DATE: Aug 23, 2017 
 * @param replacement
 * @return 返回生成option字符串
 */
public  String getOption(LinkedHashMap<String, Object> replacement){
	Set<Entry<String, Object>> entrySet=replacement.entrySet();
	Iterator<Entry<String, Object>> iterator=entrySet.iterator();
	while (iterator.hasNext()) {
		Entry<String, Object>entry=(Entry<String, Object>) iterator.next();
		//如果value非String,則將value轉為json再轉為String
		String value=entry.getValue()+"";
		Object objValue=entry.getValue() ;
		if(!(objValue instanceof String)){
			if(objValue instanceof List||objValue instanceof Object[]){//如果是數組或集合
				JSONArray jsonArray=JSONArray.fromObject(objValue);
				value=jsonArray.toString();
			}else{
				JSONObject jsonObjecct=JSONObject.fromObject(entry.getValue());
				value=jsonObjecct.toString();
			}
		}
		//根據key替換Option字符串裏的字符
		chartString=chartString.replace(entry.getKey()+"", value);
	}
	return chartString;
}
 
開發者ID:pcbaby-ch,項目名稱:echarts,代碼行數:29,代碼來源:Echart.java

示例2: updateSex

import net.sf.json.JSONArray; //導入方法依賴的package包/類
public String updateSex() {
	
	stuList = service.loadStuList();
	// 獲取男生數量和女生數量
	
	JSONArray jsonArray = JSONArray.fromObject(stuList);
	result = jsonArray.toString();
	
	try {
		response.setHeader("Cache-Control", "no-cache");
		response.setContentType("aplication/json;charset=UTF-8");
		response.getWriter().print(result);// 發送到頁麵
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	System.out.println(result);
	return null;
}
 
開發者ID:lrxzl,項目名稱:djpt,代碼行數:20,代碼來源:ChartAction.java

示例3: sendOnlineData

import net.sf.json.JSONArray; //導入方法依賴的package包/類
public void sendOnlineData(JSONArray data) throws IOException {
    String uri = address + "api/active/receiver/data";
    LinkedList<FormBodyPart> partsList = new LinkedList<>();
    String dataStr = data.toString();
    log.debug("Sending active test data: " + dataStr);
    partsList.add(new FormBodyPart("data", new StringBody(dataStr)));
    query(createPost(uri, partsList), 202);
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:9,代碼來源:LoadosophiaAPIClient.java

示例4: checkDynasty

import net.sf.json.JSONArray; //導入方法依賴的package包/類
@Action("checkDynasty")
public String checkDynasty(){
	dynastyList=bookService.checkDynasty();
	JSONArray jsonArray = JSONArray.fromObject(dynastyList);
	//ajax返回客戶端
	jsonArray.toString();
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/html;charset=UTF-8");
	try {
		response.getWriter().write(jsonArray.toString());
	} catch (IOException e) {
		e.printStackTrace();
	} 
	return null;
}
 
開發者ID:zhangjikai,項目名稱:sdudoc,代碼行數:16,代碼來源:BookAction.java

示例5: checkStyle

import net.sf.json.JSONArray; //導入方法依賴的package包/類
@Action("checkStyle")
public String checkStyle(){
	styleList=bookService.checkStyle();
	JSONArray jsonArray = JSONArray.fromObject(styleList);
	//ajax返回客戶端
	jsonArray.toString();
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/html;charset=UTF-8");
	try {
		response.getWriter().write(jsonArray.toString());
	} catch (IOException e) {
		e.printStackTrace();
	} 
	return null;
}
 
開發者ID:zhangjikai,項目名稱:sdudoc,代碼行數:16,代碼來源:BookAction.java

示例6: showAllGoodsType

import net.sf.json.JSONArray; //導入方法依賴的package包/類
/**
 * 顯示所有商品類型信息
 *
 * @param response
 */
@RequestMapping(value = "/showAllGoodsType")
@Override
public void showAllGoodsType(HttpServletResponse response)
{
    try
    {
        //查詢全部商品類型信息
        List<GoodsType8JPA> goodsTypeList = goodsTypeService
                  .findAll();

        if (goodsTypeList.size() == 0)
        {
            throw new
                      Exception("TinyShop8Controller_." +
                                          "查詢所有商品類型信息失敗!並沒有任何商品類型信息");
        }

        //寫入json
        JSONArray jsonArray = new JSONArray();

        for (Iterator<GoodsType8JPA> it = goodsTypeList.iterator(); it.hasNext(); )
        {
            JSONObject jsonObject = new JSONObject();

            GoodsType8JPA goodsType = it.next();

            //名字
            jsonObject.put("goodsTypeName", goodsType.getTypeName());
            //排序
            jsonObject.put("goodsTypeSort", goodsType.getTypeSort());
            //別名
            jsonObject.put("goodsTypeAlias", goodsType.getTypeAlias());
            //上級類型
            jsonObject.put("goodsParent", "parent");

            jsonArray.add(jsonObject);
        }

        String baseStr = "{\"total\":" + goodsTypeList.size() + ",\"rows\":";
        baseStr = baseStr + jsonArray.toString() + "}";
        returnJson(baseStr, response);
    }
    catch (Exception ex)
    {
        printStackTrace(ex);
    }
}
 
開發者ID:SessionFactory,項目名稱:tinyshop8,代碼行數:53,代碼來源:TinyShop8Controller_.java

示例7: responseArraySuccess

import net.sf.json.JSONArray; //導入方法依賴的package包/類
/** 
 * 返回成功 
 * @param obj 輸出對象 
 * @return 輸出成功的JSON格式數據 
 */  
public String responseArraySuccess(Object obj){  
    JSONArray jsonObj = null;  
    if(obj != null){  
        logger.info("後端返回對象:{}", obj);  
        JsonConfig jsonConfig = new JsonConfig();  
        jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());  
        jsonObj = JSONArray.fromObject(obj, jsonConfig);  
        logger.info("後端返回數據:" + jsonObj);  
    }  
    logger.info("輸出結果:{}", jsonObj.toString());  
    return jsonObj.toString();  
}
 
開發者ID:lonelyshine,項目名稱:xcx-specialty,代碼行數:18,代碼來源:BaseController.java

示例8: loadTree

import net.sf.json.JSONArray; //導入方法依賴的package包/類
/**
 * @return JSONArray. The JSON array of deployed web service in application.
 */
public JSONArray loadTree() {

    if (log.isDebugEnabled()) {
        log.debug("Loading tree started");
    }
    JSONArray jsonArray = createTree();
    String jsonResult = jsonArray.toString();
    if (log.isDebugEnabled()) {
        log.debug("result: " + jsonResult); // just for debug purposes-
    }

    return jsonArray;
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:17,代碼來源:DomainModelDocService.java

示例9: loadTree

import net.sf.json.JSONArray; //導入方法依賴的package包/類
/**
 * @return JSONArray. The JSON array of deployed web service in application.
 */
public JSONArray loadTree() throws JAXBException, MalformedURLException {

    if (log.isDebugEnabled()) {
        log.debug("Loading tree started");
    }
    JSONArray jsonArray = createTree();
    String jsonResult = jsonArray.toString();
    if (log.isDebugEnabled()) {
        log.debug("result: " + jsonResult); // just for debug purposes-
    }

    return jsonArray;
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:17,代碼來源:SOAEventMetaDataService.java

示例10: showAllGoods

import net.sf.json.JSONArray; //導入方法依賴的package包/類
/**
 * 顯示所有商品信息
 *
 * @param response
 */
//@RequestMapping(value = "/showAllGoods")
@Deprecated
@Override
public void showAllGoods(HttpServletResponse response)
{
    try
    {
        //首先查詢所有商品信息
        final List<Goods8JPA> goodsList = goodsService
                  .findAll();

        if (goodsList.size() == 0)
        {
            throw new
                      Exception("TinyShop8Controller_.查詢所有商品信息失敗!並沒有任何商品信息");
        }

        //寫入json
        JSONArray jsonArray = new JSONArray();

        for (Iterator<Goods8JPA> it = goodsList.iterator(); it.hasNext(); )
        {
            JSONObject jsonObject = new JSONObject();

            Goods8JPA goods = it.next();

            //名稱
            jsonObject.put("goodsName", goods.getGoodsName());
            //編號
            jsonObject.put("goodsProNo", goods.getGoodsProNo());
            //添加時間
            jsonObject.put("goodsAddDate", goods.getGoodsAddDate());
            //市場價
            jsonObject.put("goodsMarketPrice", goods.getGoodsMarketPrice());
            //所屬類型
            jsonObject.put("goodsType", "type");
            //品牌
            jsonObject.put("goodsBrand", "brand");

            jsonArray.add(jsonObject);
        }

        String baseStr = "{\"total\":" + goodsList.size() + ",\"rows\":";
        baseStr = baseStr + jsonArray.toString() + "}";
        returnJson(baseStr, response);
    }
    catch (Exception ex)
    {
        printStackTrace(ex);
    }
}
 
開發者ID:SessionFactory,項目名稱:tinyshop8,代碼行數:57,代碼來源:TinyShop8Controller_.java

示例11: auth

import net.sf.json.JSONArray; //導入方法依賴的package包/類
/**
 * 請求權限授權頁麵
 *
 * @param userId
 * @return
 */
@RequestMapping(value = AuthManageConst.PATH_AUTH, method = RequestMethod.POST)
public @ResponseBody Map<String, Object> auth(@RequestParam String r_id) {
    // 取得菜單一覽
    List<Function> functionList = functionService.listAllFunction();
    // 取得授權權限權限
    Role roleSearch = new Role();
    roleSearch.setR_id(r_id);
    Role role = roleService.getRoleById(roleSearch);
    if (role != null) {
        String roleRights = role.getR_function();
        // 判斷該權限是否存在功能權限
        if (StringUtil.notEmpty(roleRights)) {
            // 循環菜單一覽
            for (Function function : functionList) {
                // 設置權限是否存在該一級菜單的訪問權限
                function.setHasFunction(RightsHelper.testRights(roleRights, function.getF_no()));
                // 判斷是否存在此級菜單訪問權限
                if (function.isHasFunction()) {
                    // 取得二級菜單一覽
                    List<Function> subRightsList = function.getSubFunction();
                    // 循環二級菜單一覽
                    for (Function sub : subRightsList) {
                        // 設置權限是否存在該二級菜單的訪問權限
                        sub.setHasFunction(RightsHelper.testRights(roleRights, sub.getF_no()));
                        // 判斷是否存在此級菜單訪問權限
                        if (sub.isHasFunction()) {
                            // 取得三級菜單一覽
                            List<Function> nextSubRightsList = sub.getSubFunction();
                            // 循環三級菜單一覽
                            for (Function nexSub : nextSubRightsList) {
                                // 設置權限是否存在該三級菜單的訪問權限
                                nexSub.setHasFunction(RightsHelper.testRights(roleRights, nexSub.getF_no()));
                            }
                        }
                    }
                }
            }
        }
    }
    // 將菜單一覽轉換為json格式
    JSONArray arr = JSONArray.fromObject(functionList);
    // 將json格式的菜單一覽轉換為字符串
    String json = arr.toString();
    // 置換為指定的ID
    json = json.replaceAll(AuthManageConst.ATTRIBUTE_NAME_F_NO, AuthManageConst.ATTRIBUTE_NAME_ID)
            .replaceAll(AuthManageConst.ATTRIBUTE_NAME_F_NAME, AuthManageConst.ATTRIBUTE_NAME_NAME)
            .replaceAll(AuthManageConst.ATTRIBUTE_NAME_SUB_FUNCTION, AuthManageConst.ATTRIBUTE_NAME_CHILDREN)
            .replaceAll(AuthManageConst.ATTRIBUTE_NAME_HAS_FUNCTION, AuthManageConst.ATTRIBUTE_NAME_CHECKED);
    Map<String, Object> map = new HashMap<String, Object>();
    // 返回處理結果
    map.put(AuthManageConst.ATTRIBUTE_NAME_RESULT, Boolean.TRUE);
    // 返回菜單一覽
    map.put(AuthManageConst.ATTRIBUTE_NAME_Z_TREE_NODES, json);
    // 返回角色ID
    map.put(AuthManageConst.ATTRIBUTE_NAME_R_ID, r_id);
    return map;
}
 
開發者ID:PekingGo,項目名稱:ipayquery,代碼行數:64,代碼來源:AuthManageController.java


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