android project에서 작업 중입니다. api를 호출하면 예외가 throw됩니다. 나는 모든 것이 올바르게 끝났다고 생각하지만 너무 오래이 예외에 지쳤다. 이 라인오류 : java.lang.String 유형의 DOCTYPE을 JSONObject로 변환 할 수 없습니다.
response = new JSONObject(result);
가리키는 여기
org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
내 코드
public class APIConnectionManager {
private static int CONNECTION_TIMEOUT = 60000;
static JSONObject response = null;
public static final int GET = 1;
public static final int POST = 2;
/**
* Function to place a get call to the customer profile API that returns a JSONObject
*
* @param url - The path to the resource
* @param params - A list of name value pairs
* @return - JSONObject
*/
public JSONObject doCustomerAPIGet(String url, int method, List<NameValuePair> params) {
try{
// http client
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
// check the http method request type
if(method==POST){
HttpPost httpPost = new HttpPost(url);
// adding post params
if(params!=null){
httpPost.setEntity(new UrlEncodedFormEntity(params));
}
httpResponse = httpClient.execute(httpPost);
}else if (method==GET){
// appending params to the url
if (params!=null) {
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);
httpResponse = httpClient.execute(httpGet);
}
httpEntity = httpResponse.getEntity();
String result = EntityUtils.toString(httpEntity);
response = new JSONObject(result);
}catch (UnsupportedEncodingException e){
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e){
e.printStackTrace();
}
return response;
}
}
오류 마찬가지로 누군가가 이것에 알려 주시기 바랍니다 수 있습니다 응답
{"data":{"customerno":1339451,"loyalty_id":"9700354522","firstname":"raju","lastname":"king","email":"[email protected]","mobile":"9700354522","address":"1st street","city":"chennai","pincode":"600028","links":[]},"status":"success"}
을 얻고있다.
백엔드 개발자에게 문의하십시오 – Nilabja
위의 내 응답을 참조하십시오. – Raju
' Vucko