2

刚开始使用AndroidQuery处理 JSON 异步任务,我不熟悉 JSON 响应代码。在使用 AQ 方法之前,我没有收到任何错误,但现在我收到 103 TRANSFORM_ERROR。

下面是 JSON 字符串和我的代码片段。对我可能有什么问题有任何想法吗?谢谢

通过 php 返回的 JSON:

{"items":[{"_id":"1","label":"AC","title":"Advisory Circulators","description":"Provides guidance such as methods, procedures, and practices for complying with regulations and requirements.","date":"2008-03-03","gotoURL":null},{"_id":"2","label":"AD","title":"Airworthiness Directives","description":"Legally enforceable rules that apply to aircraft, aircraft engines, propellers, and appliances.","date":"2012-06-08","gotoURL":"javascript:navClickListener('bodyContent', dns + '\/wiki\/index.php\/Airworthiness_Directive #content');"},{"_id":"3","label":"CFR","title":"Code of Federal Regulations","description":"Official Rulemaking documents of the CFR in Title 14 and have been published in the Federal Register","date":"2012-01-31","gotoURL":"javascript:navClickListener('bodyContent',  dns + '\/wiki\/index.php\/Main_Page #content');"},{"_id":"4","label":"PMA","title":"Parts Manufacturer Approvals","description":"Parts Manufacturer Approvals","date":"2012-01-31","gotoURL":null},{"_id":"5","label":"SAIB","title":"Special Airworthiness Info Bulletins","description":"Bulletins issued by manufacturers to provide modification or inspection instructions.","date":"2012-01-31","gotoURL":null},{"_id":"6","label":"SFAR","title":"Special Federal Aviation Regulation","description":"Official Rulemaking documents that have changed the language of the CFR in Title 14 CFR for aviation.","date":"2012-01-31","gotoURL":null},{"_id":"7","label":"STC","title":"Supplemental Type Certificates","description":"Document issued by the Federal Aviation Administration approving a product (aircraft, engine, or propeller) modification","date":"2012-01-31","gotoURL":null},{"_id":"8","label":"TSO","title":"Technical Standard Orders","description":"Minimum performance standards issued by the FAA for specified materials, parts, processes, and appliances used on civil aircraft.","date":"2012-01-31","gotoURL":null},{"_id":"9","label":"TCDS","title":"Type Certificate Data Sheets","description":"Repository of Make and Model information of aircraft, engine or propeller including airspeed, weight, and thrust limitations, etc.","date":"2012-01-31","gotoURL":null}]}

主要活动:

public class MainActivity extends Activity implements AnimationLayout.Listener
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ...
        async_array();
    }

    AQuery aq;
    static JSONArray jArray;
    String json = null;

    public void async_array()
    {
        aq = new AQuery(this);
        String url = "http://192.168.1.11/Andaero/php/regulatory_list.php";
        aq.ajax(url, JSONArray.class, new AjaxCallback<JSONArray>()
    {

        @Override
        public void callback(String url, JSONArray json, AjaxStatus status)
        {

        if (json != null)
        {

        // successful ajax call, show status code, json content
        // jsonListCallback(json);
        Toast.makeText(aq.getContext(), status.getCode() + ":" + json.toString(), Toast.LENGTH_LONG).show();

        }

        switch (status.getCode())

        {

            case AjaxStatus.TRANSFORM_ERROR:
            Toast.makeText(aq.getContext(), "TRANSFORM_ERROR: " + status.getCode(), Toast.LENGTH_LONG).show();
            break;
            case AjaxStatus.NETWORK_ERROR:
            Toast.makeText(aq.getContext(), "NETWORK_ERROR " + status.getCode(), Toast.LENGTH_LONG).show();
            break;
            case AjaxStatus.AUTH_ERROR:
            Toast.makeText(aq.getContext(), "AUTH_ERROR" + status.getCode(), Toast.LENGTH_LONG).show();
            break;
            case AjaxStatus.NETWORK:
            Toast.makeText(aq.getContext(), "NETWORK" + status.getCode(), Toast.LENGTH_LONG).show();
            break;
            default:
            Toast.makeText(aq.getContext(), "OTHER ERROR" + status.getCode(), Toast.LENGTH_LONG).show();
            break;

        }
        }
    });
    }
4

3 回答 3

2

我从来没有使用过这个库,但我认为这是因为你得到一个对象而不是数组作为响应。

我会尝试这样的事情:

aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() ...
于 2012-05-23T23:25:10.897 回答
2

是的,你是对的,你不应该使用以下形式:

[{"unit_name":" GASPIRIN"},{"item_count":"2.000"},{"warehouse_name":"some_name"},{"unit_name":" GASPIRIN"},{"item_count":"1.000"},{"warehouse_name":"some_name2"}]

相反,您应该使用这种形式的 json:

{"unit_name":[" GASPIRIN"," GASPIRIN"],"item_count":["2.000","1.000"],"warehouse_name":["some_name","some_name2"]}

所以,这样你就不会得到 103 转换错误。

于 2012-12-17T20:53:49.867 回答
1

它不喜欢

“项目”:[。. . "

场地。我删除了它,现在它可以工作了。

于 2012-05-23T23:41:41.150 回答