示例#1
0
 public Object toJSON() throws JSONException {
   JSONObject json = new JSONObject();
   json.put("id", getId());
   json.put("owner_id", getOwnerId());
   json.put("title", getTitle());
   json.put("body", getBody());
   json.put("date_created", Util.formatDateISO8601(getCreatedDate()));
   json.put("date_modified", Util.formatDateISO8601(getModifiedDate()));
   if (isPendingDelete()) json.put("delete", true);
   if (getLocalId() != null) json.put("local_id", getLocalId());
   return json;
 }
示例#2
0
    public void fromJSON(Object object) throws JSONException {
      JSONObject json = (JSONObject) object;
      if (json.has("id")) this.key = Note.makeKey(json.getString("owner_id"), json.getString("id"));
      else this.ownerKey = UserInfo.makeKey(json.getString("owner_id"));
      this.localId = json.optString("local_id", this.localId);
      this.title = json.optString("title", this.title);
      if (json.has("body")) this.body = new Text(json.getString("body"));
      if (json.optBoolean("delete", false)) markForDeletion();

      touch();
      try {
        if (json.has("date_created"))
          this.createdDate = Util.parseDateISO8601(json.getString("date_created"));
        if (json.has("date_modified"))
          this.modifiedDate = Util.parseDateISO8601(json.getString("date_modified"));
      } catch (ParseException e) {
        throw new JSONException("Invalid date.");
      }
    }