2

JSON非同期タスクにAndroidQueryを使い始めたばかりで、JSON Responceコードに慣れていません。AQ メソッドを使用する前はエラーは発生しませんでしたが、今では 103 TRANSFORM_ERROR が発生します。

以下は、JSON 文字列と私のコード スニペットです。私が間違っている可能性があることについてのアイデアはありますか? thnx

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 に答える