okhttp onResponse访问本地变量

时间:2015-12-15 14:36:23

标签: java android okhttp

我需要通过onResponse调用中的okhttp方法获取字符串,但我无法更改onResponse内的值。我的代码在

之下
public class OkHttpTest {

private static final String TAG = "OkHttpTest";
OkHttpClient mClient = new OkHttpClient();

public String getMarkets(String url) throws IOException {
    public static String mString;
    Request mRequest = new Request.Builder()
            .url(url)
            .build();
    Call mCall = mClient.newCall(mRequest);
    mCall.enqueue(new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            Log.d(TAG, "onFailure: call failed");
        }
        @Override
        public void onResponse(Response response) throws IOException {
            if (response.isSuccessful()) {
                Log.d(TAG, "onResponse: ok");
                mString = response.body().string();  // cannot access
            } else return;
        }
    });
    return mString;  //
}   
}

我这样打电话

 String result = test.getMarkets(url);

有什么方法可以让我的工作吗?

0 个答案:

没有答案