Search in sources :

Example 1 with QAJson

use of cn.jeesoft.qa.json.QAJson in project QuickAndroid by ImKarl.

the class QAFastJsonHttpHandler method handlerResponse.

@Override
public JSON handlerResponse(Response response) throws Exception {
    String data = response.body().string();
    QAJson json = QAJsonUtils.fromJson(data);
    if (json != null) {
        if (json instanceof QAJsonObject) {
            return JSON.parseObject(data);
        } else {
            return JSON.parseArray(data);
        }
    } else {
        // TODO 更详细的错误提示
        return null;
    }
}
Also used : QAJsonObject(cn.jeesoft.qa.json.QAJsonObject) QAJson(cn.jeesoft.qa.json.QAJson)

Example 2 with QAJson

use of cn.jeesoft.qa.json.QAJson in project QuickAndroid by ImKarl.

the class QAJsonArrayHttpHandler method handlerResponse.

@Override
public JSONArray handlerResponse(Response response) throws Exception {
    String data = response.body().string();
    QAJson json = QAJsonUtils.fromJson(data);
    if (json != null && json instanceof JSONArray) {
        return (JSONArray) json;
    } else {
        // TODO 更详细的错误提示
        return null;
    }
}
Also used : QAJson(cn.jeesoft.qa.json.QAJson) JSONArray(org.json.JSONArray)

Example 3 with QAJson

use of cn.jeesoft.qa.json.QAJson in project QuickAndroid by ImKarl.

the class QAJsonObjectHttpHandler method handlerResponse.

@Override
public JSONObject handlerResponse(Response response) throws Exception {
    String data = response.body().string();
    QAJson json = QAJsonUtils.fromJson(data);
    if (json != null && json instanceof JSONObject) {
        return (JSONObject) json;
    } else {
        // TODO 更详细的错误提示
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) QAJson(cn.jeesoft.qa.json.QAJson)

Example 4 with QAJson

use of cn.jeesoft.qa.json.QAJson in project QuickAndroid by ImKarl.

the class MainActivity method testHttpParser.

/**
     * 测试HTTP请求(Parser)
     */
public void testHttpParser(final View view) {
    String url = "http://www.kuaidi100.com/query";
    QARequestParams params = new QARequestParams();
    params.putParam("type", "快递公司代号");
    params.putParam("postid", "快递单号");
    /**
         * 快递单信息
         */
    class Express implements QAJsonParser<Express> {

        int status;

        String message;

        @Override
        public Express parser(QAJson data) {
            QAJsonObject root = (QAJsonObject) data;
            this.status = root.getInt("status");
            this.message = root.getString("message");
            return this;
        }

        @Override
        public String toString() {
            return "Express [status=" + status + ", message=" + message + "]";
        }
    }
    QAHttpCallback<Express> listener = new QASimpleHttpCallback<Express>() {

        @Override
        public void onProgress(String url, long current, long total, QAHttpAction action) {
            super.onProgress(url, current, total, action);
            QAToast.show(MainActivity.this, "onProgress | " + action + " | " + current + "/" + total);
        }

        @Override
        public void onSuccessNet(String url, Express data) {
            QALog.e(url, "onSuccessNet", data);
        }

        @Override
        public void onSuccessCache(String url, Express data) {
            QALog.e(url, "onSuccessCache", data);
        }
    };
    QACore.getHttp().load(QAHttpMethod.GET, url, params, new Express(), listener);
}
Also used : QAJsonObject(cn.jeesoft.qa.json.QAJsonObject) QAJson(cn.jeesoft.qa.json.QAJson) QAJsonParser(cn.jeesoft.qa.libcore.http.QAJsonParser) QAHttpAction(cn.jeesoft.qa.libcore.http.QAHttpAction) QARequestParams(cn.jeesoft.qa.libcore.http.QARequestParams) QASimpleHttpCallback(cn.jeesoft.qa.libcore.http.QASimpleHttpCallback)

Aggregations

QAJson (cn.jeesoft.qa.json.QAJson)4 QAJsonObject (cn.jeesoft.qa.json.QAJsonObject)2 QAHttpAction (cn.jeesoft.qa.libcore.http.QAHttpAction)1 QAJsonParser (cn.jeesoft.qa.libcore.http.QAJsonParser)1 QARequestParams (cn.jeesoft.qa.libcore.http.QARequestParams)1 QASimpleHttpCallback (cn.jeesoft.qa.libcore.http.QASimpleHttpCallback)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1