无法获得字符串形式的响应
can't get respons as String
我试图向其余 Web 服务服务器发出请求。
我的请求是 JSON 格式,我的响应是一个字符串。
当我尝试执行请求时,我得到:
I/ERROR: com.androidnetworking.error.ANError: org.json.JSONException:
Value עסקה of type java.lang.String cannot be converted to JSONObject.
这是我的代码:
JSONObject res = new JSONObject();
try {//json format
res.put("ErrorCode","000");
Log.i("req",res.toString());
} catch (JSONException e) {
e.printStackTrace();
}
AndroidNetworking.post("https://gateway20.pelecard.biz/services/GetErrorMessageHe")//send the json object to the method
.addJSONObjectBody(res)
.setTag("test")
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
returnMyString(response.toString());
}
@Override
public void onError(ANError error) {
Log.i("ERROR",error.toString());
}
private void returnMyString(String myString) {
Log.i("res",myString);
}
});
如何获得字符串响应?
响应是一个字符串,但你使用的 getAsString 是错误的
AndroidNetworking.post("https://gateway20.pelecard.biz/services/GetErrorMessageHe")//send the json object to the method
.addJSONObjectBody(res)
.setTag("test")
.setPriority(Priority.HIGH)
.build()
.getAsString(new StringRequestListener() {
@Override
public void onResponse(String response) {
Log.e("TAG", "onResponse: "+response );
}
@Override
public void onError(ANError anError) {
Log.e("TAG", "onError: "+anError.getMessage() );
}
private void returnMyString(String myString) {
Log.e("res",myString);
}
});
我试图向其余 Web 服务服务器发出请求。 我的请求是 JSON 格式,我的响应是一个字符串。 当我尝试执行请求时,我得到:
I/ERROR: com.androidnetworking.error.ANError: org.json.JSONException: Value עסקה of type java.lang.String cannot be converted to JSONObject.
这是我的代码:
JSONObject res = new JSONObject();
try {//json format
res.put("ErrorCode","000");
Log.i("req",res.toString());
} catch (JSONException e) {
e.printStackTrace();
}
AndroidNetworking.post("https://gateway20.pelecard.biz/services/GetErrorMessageHe")//send the json object to the method
.addJSONObjectBody(res)
.setTag("test")
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
returnMyString(response.toString());
}
@Override
public void onError(ANError error) {
Log.i("ERROR",error.toString());
}
private void returnMyString(String myString) {
Log.i("res",myString);
}
});
如何获得字符串响应?
响应是一个字符串,但你使用的 getAsString 是错误的
AndroidNetworking.post("https://gateway20.pelecard.biz/services/GetErrorMessageHe")//send the json object to the method
.addJSONObjectBody(res)
.setTag("test")
.setPriority(Priority.HIGH)
.build()
.getAsString(new StringRequestListener() {
@Override
public void onResponse(String response) {
Log.e("TAG", "onResponse: "+response );
}
@Override
public void onError(ANError anError) {
Log.e("TAG", "onError: "+anError.getMessage() );
}
private void returnMyString(String myString) {
Log.e("res",myString);
}
});