Android JSON数组返回TRANSFORM_ERROR:103

时间:2012-05-23 23:07:20

标签: android json error-handling

刚开始使用AndroidQuery进行JSON异步任务,我不熟悉JSON Responce代码。使用AQ方法,我没有得到任何错误,但现在我得到了103 TRANSFORM_ERROR。

下面是JSON字符串和我的代码片段。对我可能有什么错误的任何想法?日Thnx

JSON通过php返回:

{"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}]}

MainActivity:

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;

        }
        }
    });
    }

3 个答案:

答案 0 :(得分:2)

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

我会尝试这样的事情:

aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() ...

答案 1 :(得分: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变换错误。

答案 2 :(得分:1)

它不喜欢

  

“项”:[。 。 。 “

字段。我删除了它,现在它可以工作。