예제 #1
0
  public JSONObject toJSON(boolean includeReviews) {
    JSONObject json = new JSONObject();
    try {
      if (categories.size() > 0) {
        JSONArray jarray = new JSONArray();
        for (String str : categories) {
          jarray.put(str);
        }
        json.put("categories", jarray);
      }
      if (pid != null && pid.length() > 0) json.put("pid", pid);
      if (getName() != null) json.put("name", getName());

      if (getAccreditations() != null && getAccreditations().length() > 0)
        json.put("accreditations", getAccreditations());
      if (getBrands() != null && getBrands().length() > 0) json.put("brands", getBrands());
      if (getPayment_types_accepted() != null && getPayment_types_accepted().length() > 0)
        json.put("payment", getPayment_types_accepted());
      if (getAka() != null && getAka().length() > 0) json.put("aka", getAka());
      if (getAvg_rating() != null && getAvg_rating().length() > 0)
        json.put("avg_rating", getAvg_rating());
      if (getBiz_since() != null && getBiz_since().length() > 0)
        json.put("in_biz_since", getBiz_since());
      if (getLanguages() != null && getLanguages().length() > 0)
        json.put("languages", getLanguages());

      if (getWhereId() != null) json.put("whereid", getWhereId());
      if (getAddress() != null) {
        Address addy = getAddress();
        json.put("location", addy.toJSON());
      }

      if (getLatlng() != null) {
        json.put("lat", getLatlng()[0]);
        json.put("long", getLatlng()[1]);
      }

      if (hours != null && hours.length() > 0) json.put("hours", hours);
      if (YPurl != null) json.put("ypurl", YPurl);
      if (biz_url != null && biz_url.length() > 0) json.put("biz_url", biz_url);

      if (includeReviews)
        if (reviews.size() > 0) {
          JSONArray jarray = new JSONArray();
          for (JSONObject jobj : reviews) {
            jarray.put(jobj);
          }
          json.put("reviews", jarray);
        }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return json;
  }