java中的get_collector_list请求

时间:2013-11-15 19:37:28

标签: surveymonkey

通过使用以下输入字符串将surveyID作为参数传递给java来尝试请求。  获得以下错误

{"status": 3, "errmsg": "No JSON object could be decoded: line 1 column 0 (char 0)"}

String input ="{\"survey_id\": p_sSurveyID, \"fields\":[\"url\"]}"; - 无法正常工作

如果surveyID是硬编码的,那么同样正常工作

String input ="{\"survey_id\":\"12345678\", \"fields\":[\"url\"]}"; - 工作

1 个答案:

答案 0 :(得分:0)

可能你没有正确连接psSurveyID。

String input ="{\"survey_id\": p_sSurveyID, \"fields\":[\"url\"]}"; -- not working

应该是

String input ="{\"survey_id\":"+ p_sSurveyID+",\"fields\":[\"url\"]}"; -- should work


  System.out.println("p_sSurveyID --- " + p_sSurveyID); 
  try 
  { 
      List<NameValuePair> parameters = new ArrayList<NameValuePair>();
      parameters.add(new NameValuePair("api_key",p_sApiKey));
      URL url = new URL(createUrl(BASE_URL+COLLECTOR_LIST_ENDPOINT,parameters));     
      HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
      conn.setDoOutput(true);
      conn.setRequestMethod("POST"); 
      conn.setRequestProperty("Content-Type", "application/json"); 
      conn.setRequestProperty("Authorization", "bearer "+p_sAuthToken);



     String input ="{\"survey_id\":"+ p_sSurveyID+",\"fields\":[\"url\"]}"; 
     OutputStream os = conn.getOutputStream();
     os.write(input.getBytes());
     os.flush();
     if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
     throw new RuntimeException("Failed : HTTP error code : " +conn.getResponseCode()); 
      }
     BufferedReader br = new BufferedReString input ="{\"survey_id\":"+ p_sSurveyID+",\"fields\":[\"url\"]}"; 
     OutputStream os = conn.getOutputStream();
     os.write(input.getBytes()); os.flush();
     if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
     throw new RuntimeException("Failed : HTTP error code : " + 
     conn.getResponseCode()); 

      }
      BufferedReader br = new BufferedReader(new InputStreamReader( (conn.getInputStream())));



    conn.disconnect();
    ader(new InputStreamReader( (conn.getInputStream()))); 
    conn.disconnect();