Java Code Examples for net.sf.json.util.JSONUtils

The following examples show how to use net.sf.json.util.JSONUtils. These examples are extracted from open source projects. 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
private JSONObject mapToJson(final DeliveryInfo deliveryInfo) {
    final JSONObject entry = new JSONObject();

    entry.element("timestamp", DateUtilities.toLong(deliveryInfo.getTimestamp()));
    entry.element("dsn", deliveryInfo.getDsn());
    entry.element("status", deliveryInfo.getStatus());

    final String relay = deliveryInfo.getRelay();
    if(StringUtils.startsWith(relay, "[")){
        entry.element("relay", JSONUtils.quote(deliveryInfo.getRelay()));
    } else {
        entry.element("relay", deliveryInfo.getRelay());
    }

    return entry;
}
 
Example 2
@Override
public String getJson() {
	if (json == null) {
		final StringBuilder b = new StringBuilder("{\"p\":" + JSONUtils.quote(path) + ",\"l\":" + live
				+ ",\"f\":" + first + ",\"h\":" + allLogsHash + ",\"u\":" + filePointer.getJson());
		if (liveNext != null) {
			b.append(",\"n\":" + JSONUtils.quote(liveNext));
		}
		b.append("}");
		json = b.toString();
	}
	return json;
}
 
Example 3
Source Project: oim-fx   Source File: RemoteModule.java    License: MIT License 4 votes vote down vote up
private void init() {

		connector = new RemoteConnector(new IoHandlerAdapter() {
			JsonParser jp = new JsonParser();

			@Override
			public void sessionOpened(IoSession session) throws Exception {
				Map<String, Object> bodyMap = new HashMap<String, Object>();
				bodyMap.put("userId", userId);
				bodyMap.put("action", action_auth);
				String json = OnlyJsonUtil.objectToJson(bodyMap);
				BytesData bd = new BytesData();
				bd.setMessage(json);
				connector.write(bd);
			}

			@Override
			public void sessionClosed(IoSession session) throws Exception {
			}

//			byte[] tempData=null;
//			private byte[] get(byte[] data){
//				if(null==tempData){
//					tempData=data;
//					return data;
//				}else{
//					int tl=tempData.length;
//					int l=data.length;
//					byte[] bytes=new byte[l];
//					for(int i=0;i<l;i++){
//						if(i<tl){
//							if(tempData[i]!=data[i]){
//								bytes[i]=data[i];
//							}else{
//								bytes[i]=tempData[i];
//							}
//						}else{
//							bytes[i]=data[i];
//						}
//					}
//					tempData=bytes;
//					return bytes;
//				}
//			}
			@Override
			public void messageReceived(IoSession session, Object message) throws Exception {
				if (message instanceof BytesData) {
					BytesData bd = (BytesData) message;
					String json = bd.getMessage();
					if (JSONUtils.mayBeJSON(json)) {
						JsonObject jo = jp.parse(json).getAsJsonObject();
						boolean hasAction = jo.has("action");
						if (hasAction) {
							String action = jo.get("action").getAsString();
							if (action_auth.equals(action)) {

							}

							if (action_client.equals(action)) {
								// String receiveId = jo.has("receiveId") ?
								// jo.get("receiveId").getAsString() : "";
								String sendId = jo.has("sendId") ? jo.get("sendId").getAsString() : "";
								byte[] bytes = bd.getBytes();
								bytes =OnlyZipUtil.unZip(bytes);
								//bytes= get(bytes);
								for (ScreenHandler sh : screenHandlerSet) {
									sh.handle(sendId, bytes);
								}
							}
							if (action_server.equals(action)) {
								EventData event = OnlyJsonUtil.getParameterValue("event", jo, EventData.class);
								handle(event);
							}
						}
					}
				}
			}
		});
		imageThread.start();
	}
 
Example 4
Source Project: jeewx-api   Source File: JwGetAutoReplyRuleAPI.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 获取自动回复规则
 * @param accessToken
 * @return
 */
public static AutoReplyInfoRule getAutoReplyInfoRule(String accessToken) throws WexinReqException{
	AutoReplyRuleGet arr = new AutoReplyRuleGet();
	arr.setAccess_token(accessToken);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(arr);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	
	AutoReplyInfoRule autoReplyInfoRule = (AutoReplyInfoRule) JSONObject.toBean(result,new CustomJsonConfig(AutoReplyInfoRule.class, "keyword_autoreply_info"));
	JSONObject keywordAutoReplyInfoJsonObj = result.getJSONObject("keyword_autoreply_info");
	if(keywordAutoReplyInfoJsonObj!=null && !JSONUtils.isNull(keywordAutoReplyInfoJsonObj)){
		/**关键词自动回复的信息 */
		JSONArray keywordAutoReplyInfos =  keywordAutoReplyInfoJsonObj.getJSONArray("list");
		if(keywordAutoReplyInfos!=null){
			List<KeyWordAutoReplyInfo> listKeyWordAutoReplyInfo = new ArrayList<KeyWordAutoReplyInfo>();
			for(int i=0;i<keywordAutoReplyInfos.size();i++){
				KeyWordAutoReplyInfo keyWordAutoReplyInfo = (KeyWordAutoReplyInfo) JSONObject.toBean(keywordAutoReplyInfos.getJSONObject(i),new CustomJsonConfig(KeyWordAutoReplyInfo.class, new String[]{"keyword_list_info","reply_list_info"}));
				/**处理关键词列表 */
				JSONArray keywordListInfos = keywordAutoReplyInfos.getJSONObject(i).getJSONArray("keyword_list_info");
				if(keywordListInfos!=null){
					List<KeywordListInfo> listKeywordListInfo = new ArrayList<KeywordListInfo>();
					for(int j=0;j<keywordListInfos.size();j++){
						KeywordListInfo keywordListInfo = (KeywordListInfo) JSONObject.toBean(keywordListInfos.getJSONObject(j),KeywordListInfo.class);
						listKeywordListInfo.add(keywordListInfo);
					}
					keyWordAutoReplyInfo.setKeyword_list_info(listKeywordListInfo);
				}
				
				/**处理关键字回复信息 */
				JSONArray replyListInfos = keywordAutoReplyInfos.getJSONObject(i).getJSONArray("reply_list_info");
				if(replyListInfos!=null){
					List<ReplyListInfo> listReplyListInfo = new ArrayList<ReplyListInfo>();
					for(int j=0;j<replyListInfos.size();j++){
						ReplyListInfo replyListInfo = (ReplyListInfo) JSONObject.toBean(keywordListInfos.getJSONObject(j),new CustomJsonConfig(ReplyListInfo.class, "news_info"));
						/**处理关键字回复相关图文消息 */
						JSONObject newsInfoJsonObj = replyListInfos.getJSONObject(j).getJSONObject("news_info");
						if(newsInfoJsonObj!=null && !JSONUtils.isNull(newsInfoJsonObj)){
							JSONArray newsInfos = newsInfoJsonObj.getJSONArray("list");
							List<WxArticleConfig> listNewsInfo = new ArrayList<WxArticleConfig>();
							for (int k = 0; k < newsInfos.size(); k++) {
								WxArticleConfig wxArticleConfig = (WxArticleConfig) JSONObject.toBean(newsInfos.getJSONObject(k), WxArticleConfig.class);
								listNewsInfo.add(wxArticleConfig);
							}
							replyListInfo.setNews_info(listNewsInfo);
						}
						listReplyListInfo.add(replyListInfo);
					}
					keyWordAutoReplyInfo.setReply_list_info(listReplyListInfo);
				}
				
				listKeyWordAutoReplyInfo.add(keyWordAutoReplyInfo);
			}
			autoReplyInfoRule.setKeyword_autoreply_info(listKeyWordAutoReplyInfo);
		}
	}
	
	return autoReplyInfoRule;
}
 
Example 5
Source Project: jeewx-api   Source File: JwMenuAPI.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 获取自定义接口配置
 * @param accessToken
 * @return
 * @throws WexinReqException
 */
public static CustomWeixinButtonConfig getAllMenuConfigure(String accessToken) throws WexinReqException{
	MenuConfigureGet cmcg = new MenuConfigureGet();
	cmcg.setAccess_token(accessToken);
	JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(cmcg);
	Object error = result.get(WeiXinConstant.RETURN_ERROR_INFO_CODE);
	
	CustomWeixinButtonConfig customWeixinButtonConfig = (CustomWeixinButtonConfig) JSONObject.toBean(result, new CustomJsonConfig(CustomWeixinButtonConfig.class,"selfmenu_info"));
	
	JSONObject selfmenuInfo = result.getJSONObject("selfmenu_info");
	if(selfmenuInfo!=null && !JSONUtils.isNull(selfmenuInfo)){ 
		/**处理父类菜单 */
		JSONArray buttons = selfmenuInfo.getJSONArray("button");
		List<WeixinButtonExtend> listButton = new ArrayList<WeixinButtonExtend>();
		for(int i=0;i<buttons.size();i++){
			WeixinButtonExtend weixinButtonExtend = (WeixinButtonExtend) JSONObject.toBean(buttons.getJSONObject(i),new CustomJsonConfig(WeixinButtonExtend.class,"sub_button"));
			/**处理子类菜单 */
			JSONObject subButtonJsonObj = buttons.getJSONObject(i).getJSONObject("sub_button");
			if(subButtonJsonObj!=null && !JSONUtils.isNull(subButtonJsonObj)){
				JSONArray subButtons = subButtonJsonObj.getJSONArray("list");
				if (subButtons != null) {
					List<WeixinButtonExtend> listSubButton = new ArrayList<WeixinButtonExtend>();
					for (int j = 0; j < subButtons.size(); j++) {
						WeixinButtonExtend subBtn = (WeixinButtonExtend) JSONObject.toBean(subButtons.getJSONObject(j), new CustomJsonConfig(WeixinButtonExtend.class,"news_info"));
						/**处理菜单关联的图文消息 */
						JSONObject newsInfoJsonObj = subButtons.getJSONObject(j).getJSONObject("news_info");
						if(newsInfoJsonObj!=null && !JSONUtils.isNull(newsInfoJsonObj)){
							JSONArray newsInfos = newsInfoJsonObj.getJSONArray("list");
							List<WxArticleConfig> listNewsInfo = new ArrayList<WxArticleConfig>();
							for (int k = 0; k < newsInfos.size(); k++) {
								WxArticleConfig wxArticleConfig = (WxArticleConfig) JSONObject.toBean(newsInfos.getJSONObject(k), WxArticleConfig.class);
								listNewsInfo.add(wxArticleConfig);
							}
							subBtn.setNews_info(listNewsInfo);
						}
						listSubButton.add(subBtn);
					}
					weixinButtonExtend.setSub_button(listSubButton);
				}
			}
			listButton.add(weixinButtonExtend);
		}
		customWeixinButtonConfig.setSelfmenu_info(listButton);
	}
	return customWeixinButtonConfig;
}