Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! Framework return json response

I`m using Play! Framework 2.0 and I'm new in this framework. How can I return just a json representation of my model in white html page?

What I'm doing is

public static void messagesJSON(){  
   List<Message> messages = Message.all();  
   renderJSON(messages);  
}

But I get Error : Cannot use a method returning Unit as an Handler

like image 748
Stas Avatar asked Jun 23 '12 08:06

Stas


People also ask

What is play JSON?

The Play JSON API provides implicit Writes for most basic types, such as Int , Double , String , and Boolean . It also supports Writes for collections of any type T that a Writes[T] exists. import play. json.

What is JSON request?

json() The json() method of the Request interface reads the request body and returns it as a promise that resolves with the result of parsing the body text as JSON .

Which of the following methods convert a JavaScript object to and from a JSON string?

Stringify a JavaScript Object Use the JavaScript function JSON.stringify() to convert it into a string. const myJSON = JSON.stringify(obj); The result will be a string following the JSON notation.


1 Answers

How about return ok(Json.toJson(Moments.all());

like image 51
Sudhir Avatar answered Sep 19 '22 17:09

Sudhir