2016-11-28 86 views
0
String pay= "[" 
      + "{" 
      + "\"internalAssessmentResponseId\" : \"Mer\\/ccclsv__AC1B752E-D079-4BA9-AA4F-46E1F8DDC11F__3048\"," 
      + "\"responses\":[" 
      + "{" 
      + "\"assessmentCreatedDate\":\"2016-11-25T11:35:54\"," 
      + "\"responseData\":[]," 
      + "\"assessmentId\":\"943\"," 
      + "}" 
      + "]," 
      + "\"addtionalInformation\":[]," 
      + "\"emailId\":\"[email protected]\"," 
      + "\"salesTeam\" :\"\"," 
      + "\"demographic\": {" 
      + "}," 
      + "\"repId\":\"AJMA-OG9OMQ\"," 
      + "\"assesseeId\":\"AGHA-2D0FVL\"," 
      + "\"assesseeType\":\"CONTACT\"," 
      + "\"typeOfResponse\":\"iPad\"," 
      + "\"userTimeZone\":\"a\"" 
      + "}" 
      + "]"; 

    HttpClient httpclient = new HttpClient(); 
     PostMethod post = new PostMethod("http://signature"); 
     post.setRequestEntity(new StringRequestEntity(pay, "application/json", null));  
     httpclient.executeMethod(post); 
     String jsonResponse = post.getResponseBodyAsString(); 
     jsonInsertRes = jsonResponse; 
     System.out.println("Response in create==>"+jsonResponse); 
     } 
catch (MalformedURLException e) 
    { 
     e.printStackTrace(); 
    } 
    catch 
    (IOException e) 
    { 
    e.printStackTrace(); 
    } 
     return jsonString.toString();   
    } 

我越來越喜歡這個 錯誤的反應不能構造org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput的情況下,問題發送請求負載在JSON數據:抽象類型只能在[Source:[email protected];其他類型信息 中實例化line:1,column:1]如何使用POST方法

回答

0

您可以嘗試發送JSON字符串作爲字符串形式參數 ,然後在服務器上讀取JSON字符串值並將字符串轉換爲Java對象(比如Message.java的對象例)。

消息msgFromJSON = new ObjectMapper()。readValue(JSONString,Message.class);

我試了幾次,它工作正常。

+0

可否請您通過代碼簡要解釋一下嗎? –