public JSONObject toJSON() { JSONObject jo = new JSONObject(); if (from != null) { jo.put("from", InternetAddress.toString(new InternetAddress[] {from})); } if (subject != null) { jo.put("subject", this.subject); } if (text != null) { jo.put("text", this.text); } if (tos != null) { jo.put("tos", InternetAddress.toString(tos)); } if (ccs != null) { jo.put("ccs", InternetAddress.toString(ccs)); } if (bccs != null) { jo.put("bccs", InternetAddress.toString(bccs)); } // if(files!=null) jo.put("form", $file.toSting(files)); if (error != null) { jo.put("error", error); } if (name != null) { jo.put("name", name); } return jo; }
public static JSONObject load(String base, String id) { File f = new File(base, id + ".json"); try { JSONObject ret = load(f); ret.put("$parent", f.getParent()); return ret; } catch (Exception ex) { ex.printStackTrace(); JOLogger.error("Can't load json [" + f + "]"); } return null; }
@Override public boolean valid(JSONObject wp) throws Exception { JSONObject row = wp.optJSONObject("$"); JSONObject ref = wp.optJSONObject("$$"); Object o = this.getFieldValue(row); if (o instanceof String && size() > 0) { try { // 處理資料過大問題 TextUtils.fixStringSize(this, row); } catch (UnsupportedEncodingException ex) { setFieldValue(row, null); // 保證資料可匯入db } } if (super.valid(wp)) { return true; } setErrData(row, null); return false; }
public static Map<String, Object> toMap(JSONObject jo) { HashMap<String, Object> m = new HashMap<String, Object>(); if (jo != null) { JSONArray names = jo.names(); if (names != null) { for (int i = 0; i < names.length(); i++) { String name = names.optString(i); Object o = jo.opt(name); if (o instanceof JSONObject) { m.put(name, toMap((JSONObject) o)); } else if (o instanceof JSONArray) { m.put(name, FJA2List.toList((JSONArray) o)); } else { m.put(name, o); } } } } return m; }
public void loadJSON(JSONObject jo) { if (jo.has("from")) { setFrom(jo.optString("from")); } if (jo.has("subject")) { setSubject(jo.optString("subject")); } if (jo.has("text")) { setText(jo.optString("text")); } if (jo.has("tos")) { setTOS(jo.optString("tos")); } if (jo.has("ccs")) { setCCS(jo.optString("ccs")); } if (jo.has("bccs")) { setBCCS(jo.optString("bccs")); } if (jo.has("files")) { setFiles(jo.optString("files")); } if (jo.has("error")) { setError(jo.optString("error")); } if (jo.has("name")) { setName(jo.optString("Name")); } }