2016-11-15 95 views
0

我發展與新澤西州一個Web服務,我有問題,因爲當我返回JSON響應瀏覽器我得到這個錯誤信息:與澤西JSON響應不工作

消息正文作家未找到Java類org.json.JSONObject和Java類型org.json.JSONObject和MIME媒體類型application/json。

這是我的編碼:

@Path("details") 
    @GET 
    @Produces("application/json") 
    public Response questionDetails(){ 
     JSONObject json = new JSONObject(); 
     json.put("kind", "Yes/No"); 
     json.put("tipeCode", 1); 
     return Response.status(200).entity(json).build(); 
    } 

在同一個Java類我從其他網站工作的例子:

@Path("test") 
     @GET 
     @Produces("application/json") 
     public Response convertFtoCfromInput() throws JSONException, SQLException { 

     JSONObject jsonObject = new JSONObject(); 
     float celsius; 
     celsius = (f - 32)*5/9; 
     jsonObject.put("F Value", f); 
     jsonObject.put("C Value", celsius); 
     jsonObject.put("number", number); 
     jsonObject.put("statement", statement); 

     String result = "@Produces(\"application/json\") Output: \n\nJSON from Path: \n\n" + jsonObject; 
     return Response.status(200).entity(result).build(); 
     } 

的代碼兩個撕成小塊非常相似每個每個其他,但我不明白爲什麼mi部分不工作。我只想返回JSON,就像示例中那樣,但沒有String。

謝謝

+0

使用正在工作的代碼片段進行測試我注意到,如果我只是返回沒有字符串的JSON對象我有同樣的錯誤,那麼,我該如何返回JSON? – proktovief

回答

0

我解決了!我很堅持,所以我沒有看到多少容易是解決我不得不轉換JSON爲String:

return Response.status(200).entity(json.toString()).build(); 

有了這一切就迎刃而解了。我很尷尬。