Extracts the KEY and value values in the JSON string in JAVA, removing the before and after spaces of value values in JSON

Source: Internet
Author: User
Tags fccs
Jsonobject jobj = jsonobject.fromobject (conditions = = null?) "{}"
				: conditions);

		Iterator it = Jobj.keys ();

		String InfoType = "FCCs";
		
		while (It.hasnext ()) {

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

			Remove all empty strings
			if (stringutil.getstring (jobj.getstring (key) = = null) {

				continue
			}

			if ("InfoType". Equals (Key)) {      //reagent type
				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: Morning 09:19:18 * @Description: Passing in String type JSON
		
		Space * @param jsonstr * @return * @exception:(exception description) */Public Jsonobject Jsonstrtrim (string jsonstr) {
		Jsonobject reagobj = Jsonobject.fromobject (JSONSTR);
		
		Remove the space for the value of the field in the 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: Morning 09:21:48 * @Description: Incoming Jsonobject Remove space * @param jsonstr * @return * @exception:(exception description)/public jsonobject Jsonstrtrim (Jsonobject jsonstr) {JSO
		Nobject reagobj = jsonstr;
		
		Remove the space for the value of the field in the 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: Morning 11:48:59 * @Description: Jsonarry 
		
		The value value in the Jsonobject place before and after the space * @param arr * @return * @exception:(exception description)/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);
				
				Remove the space for the value of the field in the 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;
	 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.