Created
May 8, 2012 11:08
-
-
Save umaar/2634285 to your computer and use it in GitHub Desktop.
[play framework2.0] return json array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Result list() | |
{ | |
ObjectNode json = Json.newObject(); | |
ArrayNode arr = json.arrayNode(); | |
ObjectNode element1 = Json.newObject(); | |
element1.put("title", 123); | |
element1.put("content", 123); | |
arr.add(element1); | |
ObjectNode element2 = Json.newObject(); | |
element2.put("title", 123); | |
element2.put("content", 123); | |
arr.add(element2); | |
json.putArray("results").addAll(arr); | |
return ok(json); | |
//{"results" : | |
// [{"title":123,"content":123}, | |
// {"title":123,"content":123}]} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment