直接上源码:
package com.m.billingplug.util; import org.json.JSONObject; /** * json管理类 * @author mhx * */ public class JsonUtil { /** * 解析json对象 * @param jsonObject json对象 * @param key json key * @return 返回json值 */ public static String paresJSON(JSONObject jsonObject, String key) { try { if(null == jsonObject) { return ""; } Object obj = jsonObject.opt(key); if(obj == null) { return ""; } else return obj.toString(); } catch (Exception e) { e.printStackTrace(); } return ""; } }