我有Play framework 2.0.4
安装。对于我拥有的 Java 应用程序,我想在 JSON
中呈现响应格式。
但是当我使用 renderJSON
时,编译器给出:
The method
renderJSON(Map<String,String>)
is undefined for the type Status
我在这里错过了什么?
public class Status extends Controller {
public static void myMethod(String url) {
Map<String, String> map = new HashMap<String, String>();
map.put("id", "1069");
map.put("url", url);
renderJSON(map);
}
}
最佳答案
我猜您正在尝试将应用程序从版本 1 移植到版本 2?在 Play 2 中,这是返回 JSON 响应的方式:
ObjectNode result = Json.newObject();
result.put("id", "1069");
result.put("url", url);
return ok(result);
您还应该看看 documentation .
关于java - 方法 renderJSON(Map<String,String>) 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14037842/