androidjsonaquery

How to use header and parameter in AQuery and get json data in android


I am Fresh in Android query,so using AndroidQuery,with header parameter here now, but another url,other post parameter is necessary.

Can not execute next callback method here,

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;
}

and call back method, Log could not print, why not call CodeCallback method.

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

Any idea, where, i am doing wrong.Thank you in advance.


Solution

  • Ok Try This Way

    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.
    }