Tag: jersey

在Java REST风格的Web服务(javax.ws..rs。*)Jersey中接收JSON对象

我有json contentType到glassfish服务器,我有java restful web服务安装程序的问题。 我使用针从Node.js POST: var options = { json: true, headers: {'Content-Type':'application/json'} } needle.post(base_url+'priorityList/',priorityList,options, function(err, resp, body){ }); 并与jersey接受: @POST @Path("/priorityList/") @Consumes(MediaType.APPLICATION_JSON) //@Consumes("text/plain") @Produces(MediaType.APPLICATION_JSON) public JSONArray priorityList(JSONObject incomingJsonString)throws IOException { } 它在glassfish服务器上给我这个错误: WARNING: StandardWrapperValve[com.mycompany.recommenderenginejava.ApplicationConfig]: Servlet.service() for servlet com.mycompany.recommenderenginejava.ApplicationConfig threw exception org.codehaus.jackson.map.exc.Unr`enter code here`ecognizedPropertyException: Unrecognized field "{"categories":["golf","banks"]}" (Class com.mycompany.recommenderenginejava.JSONObject), not marked as ignorable at […]

javax.json产生难以理解的json

我有一个Java类与两个atrributes,我转换为json使用这种方法。 我跟着这个其他答案: 返回JSONArray而不是JSONObject,Jersey JAX-RS public String toString(){ // takes advantage of toString() implementation to format {"a":"b"} JsonObject json = Json.createObjectBuilder() .add("sentence", sentence) .add( "category", category).build(); return json.toString(); } 我得到的string封装到一个string的ArrayList,并通过HTTP(我使用泽西岛)发送: return Response.status(200).entity(response).build(); 如何,节点客户端正在使用不能正确parsing它:它获取数组部分,完美地访问元素。 但不是JSON键和值; 返回undefined: jsonRespuesta = JSON.parse(body)[0]; console.log(jsonRespuesta); console.log("Frase: " +jsonRespuesta.sentence + " ,Categoria: " + jsonRespuesta.category); 返回: {"sentence":"hola","category":"2"} Frase: undefined ,Categoria: undefined 什么是失败? 如果有帮助,使用wireshark捕获数据包会将数组成员显示为string