JAVA 中 提取 JSON 字符串中的 KEY 和 VALUE 值,去除JSON中的VALUE值的 前后空格

JSONObject jobj = JSONObject.fromObject(conditions == null ? "{}"
				: conditions);

		Iterator it = jobj.keys();

		String infotype = "FCCS";
		
		while (it.hasNext()) {

			String key = it.next().toString();

			// 将所有的空串去掉
			if (StringUtil.getString(jobj.getString(key)) == null) {

				continue;
			}

			if("infoType".equals(key)){      //试剂类型
				if("FCCS".equals(jobj.getString(key))){
					infotype = "FCCS";
				}else if("HS".equals(jobj.getString(key))){
					infotype = "HS";
				}
			}

	/**
	* @Title: JsonStrTrim
	* @author : jsw
	* @date : 2012-12-7
	* @time : 上午09:19:18
	* @Description: 传入string 类型的 json字符串 去处字符串中的属性值的空格
	* @param jsonStr
	* @return
	* @exception:(异常说明)
	*/
	public JSONObject JsonStrTrim(String jsonStr){
		
		JSONObject reagobj = JSONObject.fromObject(jsonStr);
		// 取出 jsonObject 中的字段的值的空格
		Iterator itt = reagobj.keys();
		
		while (itt.hasNext()) {
			
			String key = itt.next().toString();
			String value = reagobj.getString(key);
			
			if(value == null){				
				continue ;		
			}else if("".equals(value.trim())){				
				continue ;
			}else{
				reagobj.put(key, value.trim());
			}
		}
		return reagobj;
	}
	
	/**
	* @Title: JsonStrTrim
	* @author : jsw
	* @date : 2012-12-7
	* @time : 上午09:21:48
	* @Description: 传入jsonObject 去除当中的空格
	* @param jsonStr
	* @return
	* @exception:(异常说明)
	*/
	public JSONObject JsonStrTrim(JSONObject jsonStr){
		
		JSONObject reagobj = jsonStr ;
		// 取出 jsonObject 中的字段的值的空格
		Iterator itt = reagobj.keys();
		
		while (itt.hasNext()) {
			
			String key = itt.next().toString();
			String value = reagobj.getString(key);
			
			if(value == null){				
				continue ;		
			}else if("".equals(value.trim())){				
				continue ;
			}else{
				reagobj.put(key, value.trim());
			}
		}
		return reagobj;
	}
	
	
	/**
	* @Title: JsonStrTrim
	* @author : jsw
	* @date : 2012-12-7
	* @time : 上午11:48:59
	* @Description: 将 jsonarry 的jsonObject 中的value值去处前后空格
	* @param arr
	* @return
	* @exception:(异常说明)
	*/
	public JSONArray JsonStrTrim(JSONArray arr){
		
		if( arr != null && arr.size() > 0){
			for (int i = 0; i < arr.size(); i++) {
				
				JSONObject obj = (JSONObject) arr.get(i);
				// 取出 jsonObject 中的字段的值的空格
				Iterator itt = obj.keys();
				
				while (itt.hasNext()) {
					
					String key = itt.next().toString();
					String value = obj.getString(key);
					
					if(value == null){				
						continue ;		
					}else if("".equals(value.trim())){				
						continue ;
					}else{
						obj.put(key, value.trim());
					}
				}
				arr.set(i,  obj );				
			}
		}
		return arr;
	}
	


  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值