【问题标题】:Amadeus API returns empty JSON response androidAmadeus API 返回空 JSON 响应
【发布时间】:2017-12-01 05:51:26
【问题描述】:

我试图使用Amadeus Airport Autocomplete API。但是它一直返回一个空响应。我刚刚开始向API's 请求数据,因此非常感谢您的输入。

JSON 数据如下所示:

[
  {
    "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 obj=response.getJSONObject(0); 中请求JSONobject,但它也没有返回任何内容

logcat输出如下:

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

【问题讨论】:

    标签: java android json amadeus


    【解决方案1】:

    这很可能是您的输入数据的问题,而不是 API 本身的问题。如果您提供了无效的术语,API 返回一个空列表是正常的,因为没有与您的术语匹配的机场。尝试与射手一起玩以重现此行为,例如如果 term = "" 或 "@" 您将看到一个空响应。

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 2017-09-23
      • 2021-06-24
      • 1970-01-01
      • 2020-04-08
      • 2013-11-13
      • 1970-01-01
      • 2019-02-13
      • 2018-09-28
      相关资源
      最近更新 更多