Amadeus API返回空的JSON响应android

时间:2017-12-01 05:51:27

标签: java android json amadeus

我试图使用Amadeus Airport Autocomplete API。但是它会一直返回空响应。我刚开始从API's请求数据,所以非常感谢输入。

JSONdata如下所示:

[
  {
    "value": "ROC",
    "label": "Greater Rochester International Airport [ROC]"
  },
  {
    "value": "MEE",
    "label": "La Roche - Maré Island Airport [MEE]"
  },
  {
    "value": "CAY",
    "label": "Cayenne - Rochambeau [CAY]"
  }
]

我的代码如下:

 private void RequestParams(){
        RequestParams params=new RequestParams();
        params.put("apikey",API_KEYTRUE);
        params.put("term",keyw);
        letsDoSomeNetworking(params);
    }
    private void letsDoSomeNetworking(RequestParams params){
        Log.d("PlanSky","Entered Letsdosomenetworking");
        //Async Http
        AsyncHttpClient client =new AsyncHttpClient();
        client.get(FIN_URL,params,new JsonHttpResponseHandler(){
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                Log.d("PlanSky","Success");

                try {       
                    Log.d("PlanSky", "response" +response);
                }
                catch(Exception e){
                    Log.d("PlanSky","Exception"+e);
                }
            }

            @Override
            public void onFailure(int statusCode,   Header[] headers, Throwable throwable, JSONObject errorResponse) {
                Log.d("PlanSky","Error Encountered");

            }
        }); 
}

我尝试从回复JSONobject请求JSONObject obj=response.getJSONObject(0);,但它也没有返回任何内容

logcat输出如下:

D/PlanSky: Button Clicked
D/PlanSky: Entered Letsdosomenetworking
D/PlanSky: Success
D/PlanSky: response[]

1 个答案:

答案 0 :(得分:0)

这很可能是您输入数据的问题,而不是API本身。如果您提供的是无效字词,则API返回空列表是正常的,因为没有符合您条款的机场。尝试使用射手重现此行为,例如,如果term =“”或“@”,您将看到空响应。