Hazem-Ben-Khalfallah
5/16/2013 - 8:43 AM

Parse ajax request as Json array and extract its values. Related to Gist [array Json - JS part]

Parse ajax request as Json array and extract its values. Related to Gist [array Json - JS part]

@BodyParser.Of(BodyParser.Json.class)
public static Result getParam() {
    final ArrayNode jsonNode = (ArrayNode) request().body().asJson();
    for (int i = 0; i < jsonNode.size(); i++) {
        final String paramName = jsonNode.get(i).get("name").asText();
        Logger.debug(paramName);
    }
    
    final ObjectNode result = Json.newObject();
    response().setContentType("application/json");
    return ok(Json.stringify(result));
}