【发布时间】:2020-07-19 07:49:41
【问题描述】:
我尝试向其他 Web 服务服务器发出请求。 我的请求是 JSON 格式,我的响应是一个字符串。 当我尝试执行请求时,我得到:
I/错误:com.androidnetworking.error.ANError:org.json.JSONException: java.lang.String 类型的值 עסקה 无法转换为 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);
}
});
如何获得字符串响应?
【问题讨论】:
标签: java android web-services