我想将JSON-Post中的值解析为Java-Variables。但它们总是空的!
I want to parse the values from the JSON-Post into Java-Variables. But they are always empty!
JSON-Post:
JSON-Post:
{"algID":0,"vertices":[1,2,3]}我尝试将其解析为Java-Variables:
My try to parse it into Java-Variables:
@POST @Consumes(MediaType.APPLICATION_JSON) @Path("getCloseness_vertices") public String getCloseness_vertices( @FormParam("algID") int algID, @FormParam("vertices") IntArray vertices)如果我这样尝试:
public String getCloseness_vertices(int algID)Tomcat说:
Java类int的消息体读取器,Java类型int和MIME 媒体类型application / json; charset =找不到UTF-8。
A message body reader for Java class int, and Java type int, and MIME media type application/json; charset=UTF-8 was not found.
任何帮助都会很好,我只是不明白。
Any help would be nice, I just don't get it.
推荐答案你需要创建一个可以将JSON序列化为JSON的POJO:
You need to create a POJO that Jersey can serialize the JSON to:
import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class MyPojo { public int algID; public int[] verticies; public MyPojo() {} // constructor is required }然后......
@POST @Consumes(MediaType.APPLICATION_JSON) @Path("getCloseness_vertices") public String getCloseness_vertices(MyPojo p) { int i = p.algID; }此外,您还需要包含 jersey- json jar文件。
Also you need to include the jersey-json jar file.
更多推荐
使用JSON的Jersey RESTfull服务
发布评论