0

我在 Android 查询中很新鲜,所以现在使用 AndroidQuery,这里有 header 参数,但是另一个 url,其他 post 参数是必要的。

这里不能执行下一个回调方法,

public static String getcodeJsonString(Context context2) {
    aQuery = new AQuery(context2);
    String url = Url.urlgetCode;   
    AjaxCallback<String> callBack = new AjaxCallback<String>();   
    callBack.header("username", "bimx");
    callBack.header("password", "pwd");    
    aQuery.ajax(callBack);    
    callBack.url(url).type(String.class).weakHandler(context2, "CodeCallback"); 
    return code;
}

和回调方法,Log 无法打印,为什么不调用CodeCallback方法。

public void CodeCallback(String url, String jsonString, Context context, AjaxStatus status) {
    Log.i("AQueryOputpu", "Json on String=" + jsonString);
    code = json;
}

任何想法,我在哪里做错了。提前谢谢你。

4

1 回答 1

1

好的,试试这种方式

AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
final AQuery aq = new AQuery(this);
cb.url(url).type(JSONObject.class);
aq.sync(cb);

JSONObject json = cb.getResult();
AjaxStatus status = cb.getStatus();
if (json != null && statusValid(status)) {
    // parse json object, throw if fails, etc.
}
于 2015-04-24T07:43:48.160 回答