Java Code Examples for net.sf.json.JSONObject#toBean()

The following examples show how to use net.sf.json.JSONObject#toBean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JwKfaccountAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取在线客服信息
 * kf_account	完整客服账号,格式为:账号前缀@公众号微信号
	status	客服在线状态 1:pc在线,2:手机在线。若pc和手机同时在线则为 1+2=3
	kf_id	客服工号
	auto_accept	客服设置的最大自动接入数
	accepted_case	客服当前正在接待的会话数
 * @param accessToken
 * @return
 * @throws WexinReqException
 */
public static List<WxKfaccount> getAllOnlineKfaccount(String accessToken) throws WexinReqException{
	KfOnlineAccountList kfGet = new KfOnlineAccountList();
	kfGet.setAccess_token(accessToken);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(kfGet);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	List<WxKfaccount> lstWxKfaccount = null;
	JSONArray kf_list = result.getJSONArray("kf_online_list");
	lstWxKfaccount = new ArrayList<WxKfaccount>();
	WxKfaccount kfaccount = null;
	for (int i = 0; i < kf_list.size(); i++) {
		kfaccount = (WxKfaccount) JSONObject.toBean(
				kf_list.getJSONObject(i), WxKfaccount.class);
		lstWxKfaccount.add(kfaccount);
	}
	return lstWxKfaccount;
}
 
Example 2
Source File: JwKfaccountAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取所有的客服账号信息
 * @param accessToken
 * @return
 * @throws WexinReqException
 */
public static List<WxKfaccount> getAllKfaccount(String accessToken) throws WexinReqException{
	KfaccountList kfGet = new KfaccountList();
	kfGet.setAccess_token(accessToken);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(kfGet);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	List<WxKfaccount> lstWxKfaccount = null;
	JSONArray kf_list = result.getJSONArray("kf_list");
	lstWxKfaccount = new ArrayList<WxKfaccount>();
	WxKfaccount kfaccount = null;
	for(int i = 0; i < kf_list.size() ; i++){
		kfaccount = (WxKfaccount) JSONObject.toBean( kf_list.getJSONObject(i), WxKfaccount.class);
		lstWxKfaccount.add(kfaccount);
	}
	return lstWxKfaccount;
}
 
Example 3
Source File: JwAccountAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * expire_seconds	该二维码有效时间,以秒为单位。 最大不超过1800。
	action_name	二维码类型,QR_SCENE为临时,QR_LIMIT_SCENE为永久,QR_LIMIT_STR_SCENE为永久的字符串参数值
	action_info	二维码详细信息
	scene_id	场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)
	scene_str	场景值ID(字符串形式的ID),字符串类型,长度限制为1到64,仅永久二维码支持此字段
 * @param accessToken
 * @param scene_str
 * @param action_name
 * @param expire_seconds
 * @return
 * @throws WexinReqException
 */
public static WxQrcode createQrcode(String accessToken, String scene_str,
		String action_name, String expire_seconds) throws WexinReqException {
	QrcodeCreate qrcodeCreate = new QrcodeCreate();
	qrcodeCreate.setAccess_token(accessToken);
	QrcodeActionInfo q = new QrcodeActionInfo();
	QrcodeScene ss = new QrcodeScene();
	ss.setScene_str(scene_str);
	q.setScene(ss);
	qrcodeCreate.setAction_info(q);
	qrcodeCreate.setExpire_seconds(expire_seconds);
	qrcodeCreate.setAction_name(action_name);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(qrcodeCreate);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	WxQrcode wxQrcode = null;
	wxQrcode = (WxQrcode) JSONObject.toBean(result, WxQrcode.class);
	return wxQrcode;
}
 
Example 4
Source File: SelectController.java    From cjs_ssms with GNU General Public License v2.0 6 votes vote down vote up
/**
 * users gird表查询
 *
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/userGridQuery", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> usersGridQuery(HttpServletRequest request, HttpServletResponse response) throws Exception {

  HashMap<String, String> params = HttpReqsUtil.getRequestVals(request);
  log.debug("grid通用查询参数:==>" + String.valueOf(params));

  String data = params.get("data");
  JSONObject obj = JSONObject.fromObject(data);//查询条件
  HashMap<String, String> paramsMap = (HashMap<String, String>) JSONObject.toBean(JSONObject.fromObject(obj), HashMap.class);

  Map<String, Object> resultMap = null;

  /*分页*/
  int pageIndex = Integer.parseInt(request.getParameter("pageIndex"));
  int pageSize = Integer.parseInt(request.getParameter("pageSize"));
  /*字段排序*/
  String sortField = request.getParameter("sortField");
  String sortOrder = request.getParameter("sortOrder");

  return  getGrids(pageIndex, pageSize, paramsMap);
}
 
Example 5
Source File: JwThirdAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 5、获取授权方的账户信息
 */
public static ApiGetAuthorizerRet apiGetAuthorizerInfo(ApiGetAuthorizer apiGetAuthorizer,String component_access_token) throws WexinReqException{
	String requestUrl = api_get_authorizer_info_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token);
	JSONObject param = JSONObject.fromObject(apiGetAuthorizer);
	JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", param.toString());
	ApiGetAuthorizerRet apiGetAuthorizerRet = (ApiGetAuthorizerRet)JSONObject.toBean(result, ApiGetAuthorizerRet.class);
	return apiGetAuthorizerRet;
}
 
Example 6
Source File: JwProductAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 获取商品详细
 */
public static Product getCommodity(String newAccessToken, String product_id) {
	if (newAccessToken != null) {
		String requestUrl = get_commodity_url.replace("ACCESS_TOKEN", newAccessToken);
		String json = "{\"product_id\": \""+product_id+"\"}";
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "GET", json);
		// 正常返回
		Product product = null;
		JSONObject info = result.getJSONObject("product_info");
		product = (Product)JSONObject.toBean(info, Product.class);
		return product;
	}
	return null;
}
 
Example 7
Source File: JwGroupManangerAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 根据分组ID获取分组信息
 * @return
 */
public static GroupDetailInfo getByGroupId(String newAccessToken, Integer group_id) {
	if (newAccessToken != null) {
		String requestUrl = getid_group_url.replace("ACCESS_TOKEN", newAccessToken);
		String json = "{\"group_id\": "+group_id+"}";
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json);
		// 正常返回
		GroupDetailInfo groupDetailInfo = null;
		JSONObject info = result.getJSONObject("group_detail");
		groupDetailInfo = (GroupDetailInfo)JSONObject.toBean(info, GroupDetailInfo.class);
		return groupDetailInfo;
	}
	return null;
}
 
Example 8
Source File: JwUserAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 根据user_openid 获取关注用户的基本信息
 * 
 * @param shelf_id
 * @return
 * @throws WexinReqException
 */
public static Wxuser  getWxuser(String accesstoken,String user_openid) throws WexinReqException {
	if (accesstoken != null) {
		 String requestUrl = GET_USER_URL.replace("ACCESS_TOKEN", accesstoken).replace("OPENID", user_openid);
		 JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", null);
		logger.info(result.toString());
		// 正常返回
		Wxuser wxuser = null;
		Object error = result.get("errcode");
		wxuser = (Wxuser) JSONObject.toBean(result, Wxuser.class);
		return wxuser;
	}
	return null;
}
 
Example 9
Source File: JwStockAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 减少库存
 */
public static StockRtnInfo doSubStock(String newAccessToken, StockInfo stockInfo) {
	if (newAccessToken != null) {
		String requestUrl = sub_stock_url.replace("ACCESS_TOKEN", newAccessToken);
		JSONObject obj = JSONObject.fromObject(stockInfo);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		StockRtnInfo stockRtnInfo = (StockRtnInfo)JSONObject.toBean(result, StockRtnInfo.class);
		return stockRtnInfo;
	}
	return null;
}
 
Example 10
Source File: JwSendMessageAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 使用语音、图片、视频群发消息到指定的微信分组或所有人
 * 
 * @param accesstoken
 * @param is_to_all
 *            是否发送给所有人 ,ture 发送给所有人,false 按组发送
 * @param group
 *            微信的用户组,如果is_to_all=false,则字段必须填写
 * @param wxMedia
 *            多媒体资源, 语音为voice, 图片为image,视频为video
 * @return
 * @throws WexinReqException
 */
public static SendMessageResponse sendMessageToGroupOrAllWithMedia(String accesstoken, boolean is_to_all,Group group, WxMedia wxMedia) throws WexinReqException {

	SendMessageResponse response = null;
	if (accesstoken != null) {
		String requestUrl = message_group_url.replace("ACCESS_TOKEN", accesstoken);
		try {

			String mediaId = getMediaId(accesstoken, wxMedia);
			JSONObject obj = new JSONObject();
			JSONObject filter = new JSONObject();
			JSONObject media = new JSONObject();

			filter.put("is_to_all", is_to_all);
			if (!is_to_all) {
				filter.put("group_id", group.getId());

			}
			 
			obj.put("filter", filter);

			media.put("media_id", mediaId);
			obj.put(wxMedia.getType(), media);

			obj.put("msgtype", wxMedia.getType());

			JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
			//System.out.println("微信返回的结果:" + result.toString());
			response = (SendMessageResponse) JSONObject.toBean(result, SendMessageResponse.class);
		} catch (Exception e) {

			throw new WexinReqException(e);
		}
	} else {
		throw new WexinReqException("accesstoken 为空,请检查!");
	}
	return response;
}
 
Example 11
Source File: JwShopAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 查询门店信息
 */
public static BaseInfo getshop(String newAccessToken, PoiId poiId) {
	if (newAccessToken != null) {
		String requestUrl = get_shop_url.replace("ACCESS_TOKEN", newAccessToken);
		JSONObject obj = JSONObject.fromObject(poiId);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		JSONObject info = result.getJSONObject("business");
		BaseInfo baseInfo = null;
		baseInfo = (BaseInfo)JSONObject.toBean(info, BaseInfo.class);
		return baseInfo;
	}
	return null;
}
 
Example 12
Source File: JsonMqMessageConverter.java    From zxl with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T fromMessage(org.springframework.amqp.core.Message message, Class<T> clazz) {
	String content = null;
	if (clazz == null || PrimitiveUtil.isPrimitive(clazz)) {
		return (T) DEFAULT_MESSAGE_CONVERTER.fromMessage(message);
	}
	try {
		content = new String(message.getBody(), DEFAULT_CHARSET);
		return (T) JSONObject.toBean(JSONObject.fromObject(content), clazz);
	} catch (Exception warnException) {
		LogUtil.warn(logger, "#####��Ϣת��ʧ��", warnException);
		return null;
	}
}
 
Example 13
Source File: JwThirdAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 7、设置授权方的选项信息
 */
public static AuthorizerSetOptionRet apiSetAuthorizerOption(AuthorizerSetOption authorizerSetOption,String component_access_token) throws WexinReqException{
	String requestUrl = api_set_authorizer_option_url.replace("COMPONENT_ACCESS_TOKEN", component_access_token);
	JSONObject param = JSONObject.fromObject(authorizerSetOption);
	JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", param.toString());
	AuthorizerSetOptionRet authorizerSetOptionRet = (AuthorizerSetOptionRet)JSONObject.toBean(result, AuthorizerSetOptionRet.class);
	return authorizerSetOptionRet;
}
 
Example 14
Source File: JSONHelper.java    From jeecg with Apache License 2.0 4 votes vote down vote up
public static Object json2Object(String json, Class beanClz) {
	return JSONObject.toBean(JSONObject.fromObject(json), beanClz);
}
 
Example 15
Source File: ZabbixAccessor.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
public synchronized Object execute(String method, JSON params) {
    // authが空の場合、認証する
    if (!ignoreAuthMethods.contains(method) && StringUtils.isEmpty(auth)) {
        authenticate();
    }

    Map<String, Object> request = new HashMap<String, Object>();
    request.put("jsonrpc", "2.0");
    request.put("method", method);
    request.put("params", params == null ? Collections.EMPTY_MAP : params);
    request.put("id", ++id);

    if (!ignoreAuthMethods.contains(method)) {
        request.put("auth", auth == null ? "" : auth);
    }

    String jsonRequest = JSONObject.fromObject(request).toString();
    if (log.isDebugEnabled()) {
        // パスワードのマスク化
        String str = jsonRequest;
        if (str.contains("password")) {
            str = str.replaceAll("\"password\":\".*?\"", "\"password\":\"--------\"");
        }
        if (str.contains("passwd")) {
            str = str.replaceAll("\"passwd\":\".*?\"", "\"passwd\":\"--------\"");
        }

        log.debug(str);
    }

    String jsonResponse = post(jsonRequest);
    if (log.isDebugEnabled()) {
        log.debug(jsonResponse);
    }

    JSONObject response = JSONObject.fromObject(jsonResponse);

    if (response.containsKey("error")) {
        ResponseError error = (ResponseError) JSONObject.toBean(response.getJSONObject("error"),
                ResponseError.class);

        // 認証されていない場合、再度認証して実行する
        if ("Not authorized".equals(error.getData())) {
            auth = "";
            return execute(method, params);
        }

        // エラー発生時
        AutoException exception = new AutoException("EZABBIX-000001", method);
        exception.addDetailInfo("params=" + params);
        exception.addDetailInfo(
                "error=" + ReflectionToStringBuilder.toString(error, ToStringStyle.SHORT_PREFIX_STYLE));
        throw exception;
    }

    return response.get("result");
}
 
Example 16
Source File: JsonLibUtil.java    From SpringBootBucket with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T json2Bean(String jsonStr, Class<T> objClass) {
    return (T) JSONObject.toBean(JSONObject.fromObject(jsonStr), objClass);
}
 
Example 17
Source File: JSONHelper.java    From jeewx-api with Apache License 2.0 2 votes vote down vote up
/***
 * 将将对象转换为传入类型的对象
 * 
 * @param <T>
 * @param object
 * @param beanClass
 * @return
 */
public static <T> T toBean(Object object, Class<T> beanClass) {
	JSONObject jsonObject = JSONObject.fromObject(object);

	return (T) JSONObject.toBean(jsonObject, beanClass);
}
 
Example 18
Source File: JSONHelper.java    From jeewx with Apache License 2.0 2 votes vote down vote up
/***
 * 将将对象转换为传入类型的对象
 * 
 * @param <T>
 * @param object
 * @param beanClass
 * @return
 */
public static <T> T toBean(Object object, Class<T> beanClass) {
	JSONObject jsonObject = JSONObject.fromObject(object);

	return (T) JSONObject.toBean(jsonObject, beanClass);
}
 
Example 19
Source File: JSONHelper.java    From jeewx with Apache License 2.0 2 votes vote down vote up
/***
 * 将JSON对象转换为传入类型的对象
 * 
 * @param <T>
 * @param jsonObject
 * @param beanClass
 * @return
 */
public static <T> T toBean(JSONObject jsonObject, Class<T> beanClass) {
	return (T) JSONObject.toBean(jsonObject, beanClass);
}
 
Example 20
Source File: CommonUtil.java    From ALLGO with Apache License 2.0 2 votes vote down vote up
/**
 * json to object
 * 
 * @param jsonStr
 * @param objClass
 * @return
 */
public static Object toObject(final String jsonStr, Class<?> objClass) {
	JSONObject jsObject = JSONObject.fromObject(jsonStr);
	return JSONObject.toBean(jsObject, objClass);
}