/** Serializes all the data as a single JSON string */
 @Override
 public String toString() {
   JSONObject sr = new JSONObject();
   try {
     sr.put(SERVICE, service);
     if (endpoint != null) sr.put(ENDPOINT, endpoint);
     if (service_definition != null) sr.put(SERVICE_DEFINITION, service_definition);
     if (post_data != null) sr.put(POST_DATA, post_data);
     if (service_request != null) sr.put(SERVICE_REQUEST, service_request);
   } catch (JSONException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return sr.toString();
 }
  /**
   * Creates a new, empty ServiceRequest
   *
   * <p>This does not load any user-submitted data and should only be used for initial startup.
   * Subsequent loads should be done using the JSON String version
   *
   * @param s A single service from GET Service List
   */
  public ServiceRequest(JSONObject s, Context c) {
    service = s;
    post_data = new JSONObject();

    if (service.optBoolean(Open311.METADATA)) {
      try {
        service_definition =
            Open311.getServiceDefinition(service.getString(Open311.SERVICE_CODE), c);
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    // Read in the personal info fields from Preferences
    JSONObject personalInfo = Preferences.getPersonalInfo(c);
    Iterator<?> keys = personalInfo.keys();
    while (keys.hasNext()) {
      try {
        String key = (String) keys.next();
        String value = personalInfo.getString(key);
        if (value != "") {
          post_data.put(key, value);
        }
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
 /**
  * @param parser
  * @return
  * @throws XmlPullParserException
  * @throws IOException
  * @throws JSONException
  */
 private JSONObject parseError(XmlPullParser parser)
     throws XmlPullParserException, IOException, JSONException {
   parser.require(XmlPullParser.START_TAG, ns, ERROR);
   JSONObject jo = new JSONObject();
   while (parser.next() != XmlPullParser.END_TAG) {
     if (parser.getEventType() != XmlPullParser.START_TAG) {
       continue;
     }
     String name = parser.getName();
     if (name.equals(Open311.CODE)) {
       jo.put(Open311.CODE, readElement(parser, Open311.CODE));
     } else if (name.equals(Open311.DESCRIPTION)) {
       jo.put(Open311.DESCRIPTION, readElement(parser, Open311.DESCRIPTION));
     } else {
       skip(parser);
     }
   }
   return jo;
 }
  /**
   * Adds a new server JSONObject to Preferences
   *
   * <p>This only updates the Preferences data. You still need make sure that the screen actually
   * reflects this change.
   *
   * @param dialog
   */
  private void saveNewServer(View dialog) {
    final EditText name = (EditText) dialog.findViewById(R.id.name);
    final EditText url = (EditText) dialog.findViewById(R.id.url);
    final EditText jurisdiction = (EditText) dialog.findViewById(R.id.jurisdiction);
    final EditText api_key = (EditText) dialog.findViewById(R.id.api_key);
    final ToggleButton supports_media = (ToggleButton) dialog.findViewById(R.id.supports_media);
    final Spinner format = (Spinner) dialog.findViewById(R.id.format);

    JSONObject server = new JSONObject();
    try {
      server.put(Open311.NAME, name.getText().toString());
      server.put(Open311.URL, url.getText().toString());
      server.put(Open311.JURISDICTION, jurisdiction.getText().toString());
      server.put(Open311.API_KEY, api_key.getText().toString());
      server.put(Open311.SUPPORTS_MEDIA, supports_media.isChecked());
      server.put(Open311.FORMAT, format.getSelectedItem());

      mCustomServers.put(server);
      Preferences.setCustomServers(mCustomServers, getActivity());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }