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


Java JSONObject.toString方法代码示例

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


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

示例1: responseResult

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/** 
 * 返回服务端处理结果 
 * @param obj 服务端输出对象 
 * @return 输出处理结果给前段JSON格式数据 
 * @author YANGHONGXIA 
 * @since 2015-01-06 
 */  
public String responseResult(Object obj){  
    JSONObject jsonObj = null;  
    if(obj != null){  
        logger.info("后端返回对象:{}", obj);  
        JsonConfig jsonConfig = new JsonConfig();   
        jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());  
        jsonObj = JSONObject.fromObject(obj, jsonConfig);  
        logger.info("后端返回数据:" + jsonObj);  
        if(HttpConstants.SERVICE_RESPONSE_SUCCESS_CODE.equals(jsonObj.getString(HttpConstants.SERVICE_RESPONSE_RESULT_FLAG))){  
            jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, false);  
            jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, "");  
        }else{  
            jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, true);  
            String errMsg = jsonObj.getString(HttpConstants.SERVICE_RESPONSE_RESULT_MSG);  
            jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, errMsg==null?HttpConstants.SERVICE_RESPONSE_NULL:errMsg);  
        }  
    }  
    logger.info("输出结果:{}", jsonObj.toString());  
    return jsonObj.toString();  
}
 
开发者ID:lonelyshine,项目名称:xcx-specialty,代码行数:28,代码来源:BaseController.java

示例2: getOption

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

示例3: map2jsonConverter

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
 * Converts a Map Object into JSON string.
 * @param hm
 * @return
 */
public static String map2jsonConverter(Map hm) {
    if (hm==null || hm.size()==0) {
        return "{}";
    }
    JSONObject jo = new JSONObject();
    for (Iterator it = hm.keySet().iterator(); it.hasNext();) {
        Object k = it.next();
        if (hm.get(k)==null || hm.get(k) instanceof String) {
            jo.accumulate(k.toString(), hm.get(k));
        } else if (hm.get(k) instanceof Collection || hm.get(k).getClass().isArray()) {
            jo.accumulate(k.toString(), JSONArray.fromObject(hm.get(k)).toString());
        } else {
            log.debug("map2jsonConverter: "+hm.get(k).getClass().getName());
            jo.accumulate(k.toString(), JSONObject.fromObject(hm.get(k)).toString());
        }
    }
    return jo.toString();
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:24,代码来源:JSONHelper.java

示例4: requestParams2json

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
 * Convert the request parameter map to a json string. 
 * @param request
 * @return
 */
public static String requestParams2json(ServletRequest request) {
    Map<String, String[]> params = request.getParameterMap();
    JSONObject jo = new JSONObject();
    for (Iterator<String> it=params.keySet().iterator(); it.hasNext();) {
        String k = it.next();
        String[] v = params.get(k);
        if (v==null || v.length==0) {
            continue;
        } else if (v.length==1) {
            jo.accumulate(k, v[0]);
        } else {
            jo.accumulate(k, JSONArray.fromObject(v));
        }
    }
    return jo.toString();
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:22,代码来源:JSONHelper.java

示例5: test_0

import net.sf.json.JSONObject; //导入方法依赖的package包/类
public void test_0() throws Exception {
    JSONObject obj = new JSONObject();
    obj.put("a", new A());
    String text = obj.toString();

    System.out.println(text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:BugTest2.java

示例6: sendData

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
 * Send test json data for the report
 * @return session in JSONObject
 */
public JSONObject sendData(JSONObject data) throws IOException {
    String uri = httpUtils.getDataAddress() +
            String.format("/submit.php?session_id=%s&signature=%s&test_id=%s&user_id=%s",
                    getId(), signature, testId, userId);
    uri += "&pq=0&target=labels_bulk&update=1"; //TODO: % self.kpi_target
    String dataStr = data.toString();
    log.debug("Sending active test data: " + dataStr);
    JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, dataStr), 200);
    return response.getJSONObject("result").getJSONObject("session");
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:15,代码来源:Session.java

示例7: getJsonList

import net.sf.json.JSONObject; //导入方法依赖的package包/类
@Transactional
public String getJsonList(PageBean pageBean, Map<String, Object> map,
		String order, HttpServletRequest request,
		Map<String, Object> otherParams, String[] excludes) {
	if (order == null && request != null) {
		order = " ";
		order += StringUtils.isEmpty(request.getParameter("sortname")) ? " id"
				: " " + request.getParameter("sortname");
		order += StringUtils.isEmpty(request.getParameter("sortorder")) ? " desc"
				: " " + request.getParameter("sortorder");
	}
	List<T> list = new ArrayList<T>();
	list = getList(pageBean, map, order);
	HashMap<String, Object> tempMap = new HashMap<String, Object>();
	tempMap.put(Const.Page, pageBean);
	tempMap.put(Const.Rows, list);
	tempMap.put("Total", pageBean.getDataSize());
	if (otherParams != null) {
		Iterator<Entry<String, Object>> iter = otherParams.entrySet()
				.iterator();
		while (iter.hasNext()) {
			Entry<String, Object> entry = iter.next();
			tempMap.put(entry.getKey(), entry.getValue());
		}
	}
	JsonConfig config = new JsonConfig();
	if (excludes == null) {
		excludes = new String[] {}; // 待添�?
	}
	config.setExcludes(excludes);// 出去dept属�?
	JSONObject json = JSONObject.fromObject(tempMap, config);
	return json.toString();
}
 
开发者ID:liuxuanhai,项目名称:WeiXing_xmu-2016-MrCode,代码行数:34,代码来源:BaseServiceImpl.java

示例8: responseSuccess

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/** 
 * 返回成功 
 * @param obj 输出对象 
 * @return 输出成功的JSON格式数据 
 */  
public String responseSuccess(Object obj){  
    JSONObject jsonObj = null;  
    if(obj != null){  
        logger.info("后端返回对象:{}", obj);  
        JsonConfig jsonConfig = new JsonConfig();   
        jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());  
        jsonObj = JSONObject.fromObject(obj, jsonConfig);  
        logger.info("后端返回数据:" + jsonObj);  
        jsonObj.element(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, false);  
        jsonObj.element(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, "");  
    }  
    logger.info("输出结果:{}", jsonObj.toString());  
    return jsonObj.toString();  
}
 
开发者ID:lonelyshine,项目名称:xcx-specialty,代码行数:20,代码来源:BaseController.java

示例9: responseMemberSuccess

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/** 
 * 返回成功 
 * @param obj 输出对象 
 * @return 输出成功的JSON格式数据 
 */  
public String responseMemberSuccess(Object obj){  
    JSONObject jsonObj = null;  
    if(obj != null){  
        logger.info("后端返回对象:{}", obj);  
        JsonConfig jsonConfig = new JsonConfig();   
        jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());  
        jsonObj = JSONObject.fromObject(obj, jsonConfig);  
        logger.info("后端返回数据:" + jsonObj);  
    }  
    logger.info("输出结果:{}", jsonObj.toString());  
    return jsonObj.toString();  
}
 
开发者ID:lonelyshine,项目名称:xcx-specialty,代码行数:18,代码来源:BaseController.java

示例10: responseFail

import net.sf.json.JSONObject; //导入方法依赖的package包/类
/** 
 * 返回失败 
 * @param errorMsg 错误信息 
 * @return 输出失败的JSON格式数据 
 */  
public String responseFail(String errorMsg){  
    JSONObject jsonObj = new JSONObject();  
    jsonObj.put(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, true);  
    jsonObj.put(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, errorMsg);  
    logger.info("输出结果:{}", jsonObj.toString());  
    return jsonObj.toString();  
}
 
开发者ID:lonelyshine,项目名称:xcx-specialty,代码行数:13,代码来源:BaseController.java

示例11: postToWebhook

import net.sf.json.JSONObject; //导入方法依赖的package包/类
public static void postToWebhook(String webhook, boolean deployableMessage, JSONObject message, PrintStream printStream){
    //check webhook
    if(Util.isNullOrEmpty(webhook)){
        printStream.println("[IBM Cloud DevOps] IBM_CLOUD_DEVOPS_WEBHOOK_URL not set.");
        printStream.println("[IBM Cloud DevOps] Error: Failed to notify OTC.");
    } else {
    	// set a 5 seconds timeout
    	RequestConfig defaultRequestConfig = RequestConfig.custom()
    		    .setSocketTimeout(5000)
    		    .setConnectTimeout(5000)
    		    .setConnectionRequestTimeout(5000)
    		    .build();
    	CloseableHttpClient httpClient = HttpClients.custom()
    		    .setDefaultRequestConfig(defaultRequestConfig)
    		    .build();
        HttpPost postMethod = new HttpPost(webhook);
        try {
            StringEntity data = new StringEntity(message.toString());
            postMethod.setEntity(data);
            postMethod = Proxy.addProxyInformation(postMethod);
            postMethod.addHeader("Content-Type", "application/json");
            
            if (deployableMessage) {
            	postMethod.addHeader("x-create-connection", "true");
            	printStream.println("[IBM Cloud DevOps] Sending Deployable Mapping message to webhook:");
            	printStream.println(message);
            }
            
            CloseableHttpResponse response = httpClient.execute(postMethod);

            if (response.getStatusLine().toString().matches(".*2([0-9]{2}).*")) {
                printStream.println("[IBM Cloud DevOps] Message successfully posted to webhook.");
            } else {
                printStream.println("[IBM Cloud DevOps] Message failed, response status: " + response.getStatusLine());
            }
        } catch (IOException e) {
            printStream.println("[IBM Cloud DevOps] IOException, could not post to webhook:");
            e.printStackTrace(printStream);
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cloud-devops,代码行数:42,代码来源:MessageHandler.java

示例12: generateJSONResponse

import net.sf.json.JSONObject; //导入方法依赖的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.JSONObject.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。