字符串 转 JSONObject ----JSONArray----JavaBean

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * The Class JsonToObject.
 * 
 * @author E462146
 */
// CHECKSTYLE:OFF NCSS
public class JsonToObject {

	/**
	 * The main method.
	 * 
	 * @param args
	 *            the arguments
	 */
	public static void main(String[] args) {
		String jsonStr = "{'ValueChange':{'property':'lastname','previous':'oldLastName','current':'newLastName' },'ValueChange':{'property':'lastname2','previous':'oldLastName2','current':'newLastName2' }} ";
		JSONObject jsonObject = JSONObject.fromObject(jsonStr);
		JSONArray jsonArray = jsonObject.getJSONArray("ValueChange");
		for (Object obj : jsonArray) {
			JSONObject tempJsonObject = JSONObject.fromObject(obj);
			System.out.println("property:" + tempJsonObject.get("property"));
			System.out.println("previous:" + tempJsonObject.get("previous"));
			System.out.println("current:" + tempJsonObject.get("current"));
		}
	}
}

 jar:ezmorph-1.0.6.jar

       json-lib-2.2.2-jdk15.jar

你可能感兴趣的:(json)