src/org/ohmage/domain/campaign/PromptResponse.java
@Override
	public JSONObject toJson(final boolean withId) throws JSONException {
		JSONObject result = new JSONObject();
		
		if(withId) {
			result.put(JSON_KEY_PROMPT_ID, prompt.getId());
			
			result.put(JSON_KEY_RESPONSE, getResponse());
		}
		else {
			result.put("prompt_text", prompt.getText());
			result.put("prompt_type", prompt.getType().toString());
			result.put("prompt_index", prompt.getIndex());
			result.put("prompt_unit", prompt.getUnit());
			
			if((prompt instanceof ChoicePrompt) && 
					(! (prompt instanceof CustomChoicePrompt))) {
				
				ChoicePrompt choicePrompt = (ChoicePrompt) prompt;
				Map<Integer, LabelValuePair> choices = 
						choicePrompt.getChoices();
				
				JSONObject choiceGlossary = new JSONObject();
				for(Integer choiceKey : choices.keySet()) {
					choiceGlossary.put(
							choiceKey.toString(), 
							choices.get(choiceKey).toJson());
				}
				
				result.put("prompt_choice_glossary", choiceGlossary);
			}
			
			if(this instanceof RemoteActivityPromptResponse &&
					(! wasNotDisplayed()) && (! wasSkipped())) {
				JSONArray gameResults = (JSONArray) getResponse();
				double numResults = gameResults.length();

				if(numResults != 0) {
					double total = 0;
					for(int i = 0; i < numResults; i++) {
						total += 
								gameResults.getJSONObject(i).getDouble(
										RemoteActivityPrompt.JSON_KEY_SCORE);
					}
				
					result.put("prompt_response", total / numResults);
				}
				else {
					result.put("prompt_response", "Activity Not Performed");
				}
			}
			else {
				result.put("prompt_response", getResponse());
			}
		}
		
		return result;
	}
/**
	 * Creates a JSONObject that represents this object.
	 * 
	 * @return A JSONObject that represents this object.
	 * 
	 * @throws JSONException There was a problem creating the JSONObject.
	 */
Creates a JSONObject that represents this object.

@return A JSONObject that represents this object.

@throws JSONException There was a problem creating the JSONObject.
Creates a JSONObject that represents this object . @return A JSONObject that represents this object . @throws JSONException There was a problem creating the JSONObject .
@Override
	public JSONObject toJson(final boolean withId) throws JSONException {
		JSONObject result = new JSONObject();
		if(withId) {
			result.put(JSON_KEY_PROMPT_ID, prompt.getId());
			result.put(JSON_KEY_RESPONSE, getResponse());
		}
		else {
			result.put("prompt_text", prompt.getText());
			result.put("prompt_type", prompt.getType().toString());
			result.put("prompt_index", prompt.getIndex());
			result.put("prompt_unit", prompt.getUnit());
			if((prompt instanceof ChoicePrompt) && 
					(! (prompt instanceof CustomChoicePrompt))) {
				ChoicePrompt choicePrompt = (ChoicePrompt) prompt;
				Map<Integer, LabelValuePair> choices = 
						choicePrompt.getChoices();
				JSONObject choiceGlossary = new JSONObject();
				for(Integer choiceKey : choices.keySet()) {
					choiceGlossary.put(
							choiceKey.toString(), 
							choices.get(choiceKey).toJson());
				}
				result.put("prompt_choice_glossary", choiceGlossary);
			}
			if(this instanceof RemoteActivityPromptResponse &&
					(! wasNotDisplayed()) && (! wasSkipped())) {
				JSONArray gameResults = (JSONArray) getResponse();
				double numResults = gameResults.length();
				if(numResults != 0) {
					double total = 0;
					for(int i = 0; i < numResults; i++) {
						total += 
								gameResults.getJSONObject(i).getDouble(
										RemoteActivityPrompt.JSON_KEY_SCORE);
					}
					result.put("prompt_response", total / numResults);
				}
				else {
					result.put("prompt_response", "Activity Not Performed");
				}
			}
			else {
				result.put("prompt_response", getResponse());
			}
		}
		return result;
	}
@ Override public JSONObject toJson ( final boolean withId ) throws JSONException { JSONObject result = new JSONObject ( ) ; if ( withId ) { result . put ( JSON_KEY_PROMPT_ID , prompt . getId ( ) ) ; result . put ( JSON_KEY_RESPONSE , getResponse ( ) ) ; } else { result . put ( "prompt_text" , prompt . getText ( ) ) ; result . put ( "prompt_type" , prompt . getType ( ) . toString ( ) ) ; result . put ( "prompt_index" , prompt . getIndex ( ) ) ; result . put ( "prompt_unit" , prompt . getUnit ( ) ) ; if ( ( prompt instanceof ChoicePrompt ) && ( ! ( prompt instanceof CustomChoicePrompt ) ) ) { ChoicePrompt choicePrompt = ( ChoicePrompt ) prompt ; Map < Integer , LabelValuePair > choices = choicePrompt . getChoices ( ) ; JSONObject choiceGlossary = new JSONObject ( ) ; for ( Integer choiceKey : choices . keySet ( ) ) { choiceGlossary . put ( choiceKey . toString ( ) , choices . get ( choiceKey ) . toJson ( ) ) ; } result . put ( "prompt_choice_glossary" , choiceGlossary ) ; } if ( this instanceof RemoteActivityPromptResponse && ( ! wasNotDisplayed ( ) ) && ( ! wasSkipped ( ) ) ) { JSONArray gameResults = ( JSONArray ) getResponse ( ) ; double numResults = gameResults . length ( ) ; if ( numResults != 0 ) { double total = 0 ; for ( int i = 0 ; i < numResults ; i ++ ) { total += gameResults . getJSONObject ( i ) . getDouble ( RemoteActivityPrompt . JSON_KEY_SCORE ) ; } result . put ( "prompt_response" , total / numResults ) ; } else { result . put ( "prompt_response" , "Activity Not Performed" ) ; } } else { result . put ( "prompt_response" , getResponse ( ) ) ; } } return result ; }
Creates a JSONObject that represents this object.
Creates a JSONObject that represents this object .