0

通过使用以下输入字符串将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\"]}"; - 在职的

4

1 回答 1

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();
于 2013-11-15T19:45:25.247 回答