当我进入我的网址http://localhost:8081/projectName/pathh/param告诉我的JSON对象创建获取响应JSON对象的RESTful Web服务的Java
"Employee": [{
"id": "param"
}]
这是我在Java代码。我使用Eclipse + Tom Cat服务器。
@Path("/pathh")
@GET
@Path("{parameter}")
public Response getJSONObj(@PathParam("parameter") String parameter) {
JSONObject jsonObj = new JSONObject();
JSONArray jsonarray = new JSONArray();
jsonObj.put("id", parameter);
jsonarray.put(jsonObj);
System.out.println(jsonarray);
JSONObject jsonMain = new JSONObject();
jsonMain.put("Employee", jsonarray);
System.out.println(jsonMain.toString());
System.out.println(Response.status(200).entity(jsonMain).build());
return Response.status(200).entity(jsonMain).build();
}
我得到这个错误:
HTTP状态500 - java.lang.IllegalArgumentException异常:错号码的 参数
类型异常报告
消息java.lang.IllegalArgumentException异常:参数数量错误
description s erver遇到了一个内部错误,该错误阻止了它实现此请求 。
你在同一个方法中有两个'@Path'注解吗? – alayor
是的,我有那个注释..在调试模式下一切都没问题,但与回报线似乎有一些错误.. –
我发现问题..我应该把toString()方法后jsonarray返回响应。.STATUS(200).entity(jsonarray.toString())建立(); –