Skip to content

Commit

Permalink
return JSONArray instead of json with an element set to a list
Browse files Browse the repository at this point in the history
  • Loading branch information
codersquid committed Dec 2, 2011
1 parent 6807148 commit b3c5b6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/com/miparque/restlet/PollListResource.java
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.data.CacheDirective;
Expand All @@ -24,8 +25,7 @@ public Representation represent() throws ResourceNotFoundException, JSONExceptio
getResponse().getCacheDirectives().add(CacheDirective.noCache());

List<JSONObject> polls = pollDao.getAllJson();
JSONObject json = new JSONObject();
json.put("votos", polls);
JSONArray json = new JSONArray(polls);

JsonRepresentation jr = new JsonRepresentation(json);
jr.setCharacterSet(CharacterSet.UTF_8);
Expand Down
8 changes: 4 additions & 4 deletions src/com/miparque/restlet/VotoHistoryListResource.java
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.data.CacheDirective;
Expand Down Expand Up @@ -33,10 +34,10 @@ public class VotoHistoryListResource extends ServerResource {
*
* @return list of user choice histories in reverse chronology
* <pre>
* {"history":[
* {
* {"pollId":"801","timeStamp":"1322237594991","choiceId":"401","userId":"123", * "timeOfVote":"2011.11.25","rowid":"1201"},
* {"pollId":"801","timeStamp":"1322237578645","choiceId":"402","userId":"123","timeOfVote":"2011.11.25","rowid":"1001"}
* ]}
* }
* </pre>
* @throws ResourceNotFoundException
* @throws JSONException
Expand All @@ -57,8 +58,7 @@ public Representation representPollHistory() throws ResourceNotFoundException, J
} else {
history= vhDao.getUserPollHistoryJsonList(id, pollId);
}
JSONObject json = new JSONObject();
json.put("history", history);
JSONArray json = new JSONArray(history);
JsonRepresentation jr = new JsonRepresentation(json);
jr.setCharacterSet(CharacterSet.UTF_8);
return jr;
Expand Down

0 comments on commit b3c5b6a

Please sign in to comment.