在使用okhttp成功接收json数据后进行打印log:
@Override
public void onResponse(Response response) throws IOException {
// Log.i(“log”, ” onResponse() reuslt=” + response.body().string());
JSONObject jsonobject =JSON.parseObject(response.body().string());
Log.d(“log”,”数据成功 码:”+jsonobject.get(“code”));
}
错误原因:由于某处两次都调用了response.body().string();
导致closed,有且只能调用一次
错:
09-13 17:41:22.763 19725-21188/mhwh.wow E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: mhwh.wow, PID: 19725
java.lang.IllegalStateException: closed
at com.squareup.okhttp.internal.http.HttpConnection
FixedLengthSource.read(HttpConnection.java:454)atokio.Buffer.writeAll(Buffer.java:574)atokio.RealBufferedSource.readByteArray(RealBufferedSource.java:87)atcom.squareup.okhttp.ResponseBody.bytes(ResponseBody.java:56)atcom.squareup.okhttp.ResponseBody.string(ResponseBody.java:82)atmhwh.wow.fragment.FragmentThreeTimeRecord
1.onResponse(FragmentThreeTimeRecord.java:149)
at com.squareup.okhttp.Call
AsyncCall.execute(Call.java:150)atcom.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)atjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)atjava.util.concurrent.ThreadPoolExecutor
Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)