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

The following examples show how to use net.sf.json.JSONObject#get() . 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: JsonTools.java    From sso-oauth2 with Apache License 2.0 6 votes vote down vote up
/**
* 
* json转换map.
* <br>详细说明
* @param jsonStr json字符串
* @return
* @return Map<String,Object> 集合
* @throws
* @author slj
*/
public static Map<String, Object> parseJSON2Map(String jsonStr) {
	ListOrderedMap map = new ListOrderedMap();
	// System.out.println(jsonStr);
	// 最外层解析
	JSONObject json = JSONObject.fromObject(jsonStr);
	for (Object k : json.keySet()) {
		Object v = json.get(k);
		// 如果内层还是数组的话,继续解析
		if (v instanceof JSONArray) {
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			Iterator<JSONObject> it = ((JSONArray) v).iterator();
			while (it.hasNext()) {
				JSONObject json2 = it.next();
				list.add(parseJSON2Map(json2.toString()));
			}
			map.put(k.toString(), list);
		} else {
			map.put(k.toString(), v);
		}
	}
	return map;
}
 
Example 3
Source File: JSONHelper.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/***
 * 将JSON文本反序列化为主从关系的实体
 * 
 * @param <T>泛型T 代表主实体类型
 * @param <D1>泛型D1 代表从实体类型
 * @param <D2>泛型D2 代表从实体类型
 * @param jsonString
 *            JSON文本
 * @param mainClass
 *            主实体类型
 * @param detailName1
 *            从实体类在主实体类中的属性
 * @param detailClass1
 *            从实体类型
 * @param detailName2
 *            从实体类在主实体类中的属性
 * @param detailClass2
 *            从实体类型
 * @return
 */
public static <T, D1, D2> T toBean(String jsonString, Class<T> mainClass,
		String detailName1, Class<D1> detailClass1, String detailName2,
		Class<D2> detailClass2) {
	JSONObject jsonObject = JSONObject.fromObject(jsonString);
	JSONArray jsonArray1 = (JSONArray) jsonObject.get(detailName1);
	JSONArray jsonArray2 = (JSONArray) jsonObject.get(detailName2);

	T mainEntity = JSONHelper.toBean(jsonObject, mainClass);
	List<D1> detailList1 = JSONHelper.toList(jsonArray1, detailClass1);
	List<D2> detailList2 = JSONHelper.toList(jsonArray2, detailClass2);

	try {
		BeanUtils.setProperty(mainEntity, detailName1, detailList1);
		BeanUtils.setProperty(mainEntity, detailName2, detailList2);
	} catch (Exception ex) {
		throw new RuntimeException("主从关系JSON反序列化实体失败!");
	}

	return mainEntity;
}
 
Example 4
Source File: JwDataCubeAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取消息发送分布月数据
 * @param bDate 起始时间
 * @param eDate 结束时间
 * @return
 * @throws WexinReqException
 */
public static List<WxDataCubeStreamMsgDistMonthInfo> getWxDataCubeStreamMsgDistMonthInfo(String accesstoken,String bDate,String eDate) throws WexinReqException {
	if (accesstoken != null) {
		
		// 封装请求参数
		WxDataCubeStreamMsgDistMonthParam msgParam = new WxDataCubeStreamMsgDistMonthParam();
		msgParam.setAccess_token(accesstoken);
		msgParam.setBegin_date(bDate);
		msgParam.setEnd_date(eDate);
		
		// 调用接口
		String requestUrl = GETUPSTREAMMSGDISTMONTH_URL.replace("ACCESS_TOKEN", accesstoken);
		JSONObject obj = JSONObject.fromObject(msgParam);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		Object error = result.get("errcode");

		// 无错误消息时 返回数据对象
		JSONArray arrayResult = result.getJSONArray("list");
		// 正常返回
		List<WxDataCubeStreamMsgDistMonthInfo> msgInfoList = null;
		msgInfoList=JSONHelper.toList(arrayResult, WxDataCubeStreamMsgDistMonthInfo.class);
		return msgInfoList;
	}
	return null;
}
 
Example 5
Source File: JwDataCubeAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取消息发送月数据
 * @param bDate 起始时间
 * @param eDate 结束时间
 * @return
 * @throws WexinReqException
 */
public static List<WxDataCubeStreamMsgMonthInfo> getWxDataCubeStreamMsgMonthInfo(String accesstoken,String bDate,String eDate) throws WexinReqException {
	if (accesstoken != null) {
		
		// 封装请求参数
		WxDataCubeStreamMsgMonthParam msgParam = new WxDataCubeStreamMsgMonthParam();
		msgParam.setAccess_token(accesstoken);
		msgParam.setBegin_date(bDate);
		msgParam.setEnd_date(eDate);
		
		// 调用接口
		String requestUrl = GETUPSTREAMMSGMONTH_URL.replace("ACCESS_TOKEN", accesstoken);
		JSONObject obj = JSONObject.fromObject(msgParam);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		Object error = result.get("errcode");

		// 无错误消息时 返回数据对象
		JSONArray arrayResult = result.getJSONArray("list");
		// 正常返回
		List<WxDataCubeStreamMsgMonthInfo> msgInfoList = null;
		msgInfoList=JSONHelper.toList(arrayResult, WxDataCubeStreamMsgMonthInfo.class);
		return msgInfoList;
	}
	return null;
}
 
Example 6
Source File: DingTalkGlobalConfig.java    From dingtalk-plugin with MIT License 6 votes vote down vote up
@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
//    System.out.println("============ old form data =============");
//    System.out.println(json.toString());
    Object robotConfigObj = json.get("robotConfigs");
    if (robotConfigObj == null) {
      json.put("robotConfigs", new JSONArray());
    } else {
      JSONArray robotConfigs = JSONArray.fromObject(robotConfigObj);
      robotConfigs.removeIf(item -> {
        JSONObject jsonObject = JSONObject.fromObject(item);
        String webhook = jsonObject.getString("webhook");
        return StringUtils.isEmpty(webhook);
      });
    }
//    System.out.println("============ new form data =============");
//    System.out.println(json.toString());
    req.bindJSON(this, json);
    this.save();
    return super.configure(req, json);
  }
 
Example 7
Source File: JwDataCubeAPI.java    From jeewx-api with Apache License 2.0 6 votes vote down vote up
/**
 * 获取消息发送分布周数据
 * @param bDate 起始时间
 * @param eDate 结束时间
 * @return
 * @throws WexinReqException
 */
public static List<WxDataCubeStreamMsgDistWeekInfo> getWxDataCubeStreamMsgDistWeekInfo(String accesstoken,String bDate,String eDate) throws WexinReqException {
	if (accesstoken != null) {
		
		// 封装请求参数
		WxDataCubeStreamMsgDistWeekParam msgParam = new WxDataCubeStreamMsgDistWeekParam();
		msgParam.setAccess_token(accesstoken);
		msgParam.setBegin_date(bDate);
		msgParam.setEnd_date(eDate);
		
		
		// 调用接口
		String requestUrl = GETUPSTREAMMSGDISTWEEK_URL.replace("ACCESS_TOKEN", accesstoken);
		JSONObject obj = JSONObject.fromObject(msgParam);
		JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString());
		Object error = result.get("errcode");

		// 无错误消息时 返回数据对象
		JSONArray arrayResult = result.getJSONArray("list");
		// 正常返回
		List<WxDataCubeStreamMsgDistWeekInfo> msgInfoList = null;
		msgInfoList=JSONHelper.toList(arrayResult, WxDataCubeStreamMsgDistWeekInfo.class);
		return msgInfoList;
	}
	return null;
}
 
Example 8
Source File: JSONHelper.java    From jeecg with Apache License 2.0 6 votes vote down vote up
/***
 * 将对象转换为List<Map<String,Object>>
 * 
 * @param object
 * @return
 */
// 返回非实体类型(Map<String,Object>)的List
public static List<Map<String, Object>> toList(Object object) {
	List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	JSONArray jsonArray = JSONArray.fromObject(object);
	for (Object obj : jsonArray) {
		JSONObject jsonObject = (JSONObject) obj;
		Map<String, Object> map = new HashMap<String, Object>();
		Iterator it = jsonObject.keys();
		while (it.hasNext()) {
			String key = (String) it.next();
			Object value = jsonObject.get(key);
			map.put((String) key, value);
		}
		list.add(map);
	}
	return list;
}
 
Example 9
Source File: JSONHelper.java    From jeecg with Apache License 2.0 6 votes vote down vote up
/***
 * 将JSON文本反序列化为主从关系的实体
 * 
 * @param <T>泛型T 代表主实体类型
 * @param <D1>泛型D1 代表从实体类型
 * @param <D2>泛型D2 代表从实体类型
 * @param jsonString
 *            JSON文本
 * @param mainClass
 *            主实体类型
 * @param detailName1
 *            从实体类在主实体类中的属性
 * @param detailClass1
 *            从实体类型
 * @param detailName2
 *            从实体类在主实体类中的属性
 * @param detailClass2
 *            从实体类型
 * @return
 */
public static <T, D1, D2> T toBean(String jsonString, Class<T> mainClass,
		String detailName1, Class<D1> detailClass1, String detailName2,
		Class<D2> detailClass2) {
	JSONObject jsonObject = JSONObject.fromObject(jsonString);
	JSONArray jsonArray1 = (JSONArray) jsonObject.get(detailName1);
	JSONArray jsonArray2 = (JSONArray) jsonObject.get(detailName2);

	T mainEntity = JSONHelper.toBean(jsonObject, mainClass);
	List<D1> detailList1 = JSONHelper.toList(jsonArray1, detailClass1);
	List<D2> detailList2 = JSONHelper.toList(jsonArray2, detailClass2);

	try {
		BeanUtils.setProperty(mainEntity, detailName1, detailList1);
		BeanUtils.setProperty(mainEntity, detailName2, detailList2);
	} catch (Exception ex) {
		throw new RuntimeException("主从关系JSON反序列化实体失败!");
	}

	return mainEntity;
}
 
Example 10
Source File: TemplateVO.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取json的某个 String 的值,并进行xss过滤
 */
public String getJsonStringAndFilterXSS(JSONObject json, String key){
	if(json == null){
		return "";
	}
	if(json.get(key) == null){
		return "";
	}
	
	return StringUtil.filterXss(getJsonString(json.getString(key)));
}
 
Example 11
Source File: JwGroupAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 创建分组信息
 * @param accesstoken
 * @param groupName
 * @return
 * @throws WexinReqException
 */
public static GroupCreate createGroup(String accesstoken ,String groupName ) throws WexinReqException{
	GroupCreate c = new GroupCreate();
	c.setAccess_token(accesstoken);
	Group g = new Group();
	g.setName(groupName);
	c.setGroup(g);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(c);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	GroupCreate groupCreate = null;
	groupCreate = (GroupCreate) JSONObject.toBean(result, GroupCreate.class);
	return groupCreate;
}
 
Example 12
Source File: RemoteService.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Invoke the XML HTTP request.
 */
public String requestFORGE(String message, String botid, String server, String apikey, int limit, String hint, Network network) throws Exception {
	try {
		log("FORGE", Level.INFO, message);
		String url = "";
		if (server == null || server.isEmpty()) {
			server = "http://www.personalityforge.com";
		} else {
			server = server.toLowerCase();
			if (!server.startsWith("http")) {
				server = "http://" + server;
			}
		}
		url = server + "/api/chat/?apiKey=" + apikey + "&chatBotID=" + botid + "&message=" + message + "&externalID=123";
		String json = Utils.httpGET(url);
		JSONObject root = (JSONObject)JSONSerializer.toJSON(json);
		if (root == null) {
			return null;
		}
		Object response = root.get("message");
		if (!(response instanceof JSONObject)) {
			return null;
		}
		response = ((JSONObject)response).get("message");
		if (!(response instanceof String)) {
			return null;
		}
		return (String)response;
	} catch (Exception exception) {
		log(exception);
	}
	return null;
}
 
Example 13
Source File: ConceptMappingServiceImpl.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public Set<Integer> getAllConceptIds(Integer conceptSetId) {
	JSONObject set1=OHDSIApis.querybyconceptSetid(conceptSetId);
	Set<Integer> conceptIds=new HashSet<Integer>();
	JSONObject jo=(JSONObject) set1.get("expression");
	JSONArray ja=(JSONArray) jo.get("items");
	if(ja.size()>0){
		for(int i=0;i<ja.size();i++){
			JSONObject conceptunit=(JSONObject) ja.get(i);
			JSONObject concept=(JSONObject) conceptunit.get("concept");
			conceptIds.add(concept.getInt("CONCEPT_ID"));
		}
	}
	return conceptIds;
}
 
Example 14
Source File: WeiXinUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 网页授权获取用户的个人信息
 * @param code 如果用户同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE,授权成功会get方式传过来
 * @return	<li>若成功,返回{@link UserInfo} (无 subscribeTime 项)
 * 			<li>若失败,返回null
 */
public UserInfo getOauth2UserInfo(String code){
	HttpUtil httpUtil = new HttpUtil();
	HttpResponse httpResponse = httpUtil.get(OAUTH2_ACCESS_TOKEN_URL.replace("APPID", this.appId).replace("SECRET", this.appSecret).replace("CODE", code));
	JSONObject json = JSONObject.fromObject(httpResponse.getContent());
	if(json.get("errcode") == null){
		//没有出错,获取网页access_token成功
		HttpResponse res = httpUtil.get(OAUTH2_USER_INFO_URL.replace("ACCESS_TOKEN", json.getString("access_token")).replace("OPENID", json.getString("openid")));
		JSONObject j = JSONObject.fromObject(res.getContent());
		if(j.get("errcode") == null){
			UserInfo userInfo = new UserInfo();
			userInfo.setCity(j.getString("city"));
			userInfo.setOpenid(j.getString("openid"));
			userInfo.setNickname(j.getString("nickname"));
			userInfo.setSex(j.getInt("sex"));
			userInfo.setProvince(j.getString("province"));
			userInfo.setCountry(j.getString("country"));
			userInfo.setHeadImgUrl(j.getString("headimgurl"));
			userInfo.setLanguage("zh_CN");
			return userInfo;
		}else{
			debug("获取网页授权用户信息失败!返回值:"+res.getContent());
		}
	}else{
		debug("获取网页授权access_token失败!返回值:"+httpResponse.getContent());
	}
	
	return null;
}
 
Example 15
Source File: OrderNumFillRule.java    From jeecg with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(String paramJson) {
	String prefix="CN";
	//订单前缀默认为CN 如果规则参数不为空,则取自定义前缀
	if(paramJson!=null && !"".equals(paramJson)){
		JSONObject jsonObject = JSONObject.fromObject(paramJson);
		Object obj = jsonObject.get("prefix");
		if(obj!=null)prefix=obj.toString();
	}
	SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
	int random=RandomUtils.nextInt(90)+10;
	return prefix+format.format(new Date())+random;
}
 
Example 16
Source File: WordServiceImpl.java    From yunsleLive_room with MIT License 5 votes vote down vote up
@Override
public boolean filterWords(String str) {
    //调用工具类
    JSONObject data = wordUtils.filterWords(str);
    //检测API返回的状态
    if(!(boolean)data.get("status")) {
        //发送给activeMQ,由敏感词拦截系统作响应
        queueSender.send("yunsle.filter", str);
        return false;
    }else {
        return true;
    }
}
 
Example 17
Source File: CredentialApi.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@POST
@WebMethod(name = "")
public CreateResponse create(@JsonBody JSONObject body, StaplerRequest request) throws IOException {

    User authenticatedUser =  User.current();
    if(authenticatedUser == null){
        throw new ServiceException.UnauthorizedException("No authenticated user found");
    }

    JSONObject jsonObject = body.getJSONObject("credentials");
    final IdCredentials credentials = request.bindJSON(IdCredentials.class, jsonObject);

    String domainName = DOMAIN_NAME;

    if(jsonObject.get("domain") != null && jsonObject.get("domain") instanceof String){
        domainName = (String) jsonObject.get("domain");
    }

    CredentialsUtils.createCredentialsInUserStore(credentials, authenticatedUser, domainName,
            ImmutableList.of(new BlueOceanDomainSpecification()));

    CredentialsStoreAction.DomainWrapper domainWrapper = credentialStoreAction.getDomain(domainName);


    if(domainWrapper != null) {
        CredentialsStoreAction.CredentialsWrapper credentialsWrapper = domainWrapper.getCredential(credentials.getId());
        if (credentialsWrapper != null){
            return new CreateResponse(
                    new CredentialApi.Credential(
                            credentialsWrapper,
                            getLink().rel("domains").rel(domainName).rel("credentials")));
        }
    }

    //this should never happen
    throw new ServiceException.UnexpectedErrorException("Unexpected error, failed to create credential");
}
 
Example 18
Source File: JwMediaAPI.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
/**
 * 下载多媒体
 * @param accessToke
 * @param media_id
 * @param filePath
 * @return
 * @throws WexinReqException
 */
public static WxDwonload downMedia(String accessToke,String media_id,String filePath) throws WexinReqException{
	DownloadMedia downloadMedia = new DownloadMedia();
	downloadMedia.setAccess_token(accessToke);
	downloadMedia.setFilePath(filePath);
	downloadMedia.setMedia_id(media_id);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(downloadMedia);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	WxDwonload wxMedia = null;
	wxMedia = (WxDwonload) JSONObject.toBean(result, WxDwonload.class);
	return wxMedia;
}
 
Example 19
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 20
Source File: TemplateUtil.java    From jeecg with Apache License 2.0 4 votes vote down vote up
/**
    * 解析经过leipiFormDesign.parse_form()格式化的表单模板html
    * @param content
    * @return
    */
public Map<String,Object> processor(String content) {
		
	Map<String,Object> map = new HashMap<String,Object>();
	try {
		JSONObject jsonObj = JSONObject.fromObject(content);
		String template  = (String)jsonObj.get("template");
		String parseHtml = (String)jsonObj.get("parse");
		JSONArray jsonArray = new JSONArray().fromObject(jsonObj.get("data"));
		map.put("template", template);
		//1.利用正则,取得所有的input标签
		String rexEg = "(<input[^>]*>)";
		Pattern p = Pattern.compile(rexEg);
		Matcher m = p.matcher(parseHtml);
		List<String> result=new ArrayList<String>();
		while(m.find()){
			result.add(m.group());
		}
		Map<String, Object> tableData = null;
		int index = 0;
		for(int i=0;i<result.size();i++){
			//2,利用正则,匹配标签中是否含有listctrl字段
			String ctrlExp = "(listctrl)";
			Pattern ctrlP = Pattern.compile(ctrlExp);
			Matcher ctrlM = ctrlP.matcher(result.get(i));
			//2.1 如果含有,则插入解析data.生成html后,讲html替换
			if(ctrlM.find()){
				tableData = new HashMap<String, Object>();
				for(int j=index;j<jsonArray.size();j++){
					JSONObject item = jsonArray.getJSONObject(j);
					if("listctrl".equals(item.getString("leipiplugins"))){
						String tempHtml = GetListctrl(jsonArray.getJSONObject(j),tableData,"");
						parseHtml = parseHtml.replace(result.get(i), tempHtml);
						index =j+1;
					}
				}
			}
		}
		
		map.put("parseHtml",parseHtml);
	} catch(Exception e) {
		e.printStackTrace();
	}
	return map;
}