ListView 未使用 Retrofit 显示所有 JSON 数据

我正在尝试将所有 JSON 结果放入我的列表视图中。我已成功检索数据,但它只显示一个数据(例如,如果 JNE,只显示 OKE 结果)。我正在使用改造。下面是我想在我的列表视图中显示的文档中的示例 JSON 数据。请帮助我为什么它没有显示所有结果。谢谢你。


{

 "rajaongkir":{

  "query":{

     "origin":"501",

     "destination":"114",

     "weight":1700,

     "courier":"jne"

  },

  "status":{

     "code":200,

     "description":"OK"

  },

  "origin_details":{

     "city_id":"501",

     "province_id":"5",

     "province":"DI Yogyakarta",

     "type":"Kota",

     "city_name":"Yogyakarta",

     "postal_code":"55000"

  },

  "destination_details":{

     "city_id":"114",

     "province_id":"1",

     "province":"Bali",

     "type":"Kota",

     "city_name":"Denpasar",

     "postal_code":"80000"

  },

  "results":[

     {

        "code":"jne",

        "name":"Jalur Nugraha Ekakurir (JNE)",

        "costs":[

           {

              "service":"OKE",

              "description":"Ongkos Kirim Ekonomis",

              "cost":[

                 {

                    "value":38000,

                    "etd":"4-5",

                    "note":""

                 }

              ]

           },

           {

              "service":"REG",

              "description":"Layanan Reguler",

              "cost":[

                 {

                    "value":44000,

                    "etd":"2-3",

                    "note":""

                 }

              ]

           },

           {

              "service":"SPS",

              "description":"Super Speed",

              "cost":[

                 {

                    "value":349000,

                    "etd":"",

                    "note":""

                 }

              ]

           },

           {

              "service":"YES",

              "description":"Yakin Esok Sampai",

              "cost":[

                 {

                    "value":98000,

                    "etd":"1-1",

                    "note":""

                 }

              ]

           }

        ]

     }

    ]

    }

    }


慕桂英3389331
浏览 75回答 1
1回答

慕的地8271018

public void getCoast(String origin,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String destination,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String weight,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String courier) {&nbsp; &nbsp; Retrofit retrofit = new Retrofit.Builder()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .baseUrl(ApiUrl.URL_ROOT_HTTPS)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .addConverterFactory(GsonConverterFactory.create())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .build();&nbsp; &nbsp; ApiService service = retrofit.create(ApiService.class);&nbsp; &nbsp; Call<ItemCost> call = service.getCost(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "c5333cdcc37b3511c909088d99587fd8",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; origin,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destination,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; weight,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; courier&nbsp; &nbsp; );&nbsp; &nbsp; call.enqueue(new Callback<ItemCost>() {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onResponse(Call<ItemCost> call, Response<ItemCost> response) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Log.v("wow", "json : " + new Gson().toJson(response));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressDialog.dismiss();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (response.isSuccessful()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int statusCode = response.body().getRajaongkir().getStatus().getCode();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (statusCode == 200) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; View alertLayout = inflater.inflate(R.layout.custom_results, null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert = new AlertDialog.Builder(MainActivity.this);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert.setTitle("Result Cost");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert.setMessage("this result your search");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert.setView(alertLayout);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert.setCancelable(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ad = alert.show();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String originCity = response.body().getRajaongkir().getOriginDetails().getCityName();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String originPostalCode = response.body().getRajaongkir().getOriginDetails().getPostalCode();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String destinationCity = response.body().getRajaongkir().getDestinationDetails().getCityName();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String destinationPostalCode = response.body().getRajaongkir().getDestinationDetails().getPostalCode();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //results&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<com.bagicode.cekongkir.model.cost.Result> ListResults = response.body().getRajaongkir().getResults();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //costs&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List<com.bagicode.cekongkir.model.cost.Cost> ListCosts = response.body().getRajaongkir().getResults().get(0).getCosts();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//cost&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List<com.bagicode.cekongkir.model.cost.Cost_> ListCost = response.body().getRajaongkir().getResults().get(0).getCosts().get(0).getCost();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mListView = (ListView) alertLayout.findViewById(R.id.listItem);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adapter_results = new ResultsAdapter(MainActivity.this, originCity, originPostalCode, destinationCity, destinationPostalCode, ListResults, ListCosts, ListCost);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mListView.setAdapter(adapter_results);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mListView.setClickable(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adapter_results.notifyDataSetChanged();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String message = response.body().getRajaongkir().getStatus().getDescription();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String error = "Error Retrive Data from Server !!!";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.makeText(MainActivity.this, error, Toast.LENGTH_SHORT).show();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onFailure(Call<ItemCost> call, Throwable t) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressDialog.dismiss();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.makeText(MainActivity.this, "Message : Error " + t.getMessage(), Toast.LENGTH_SHORT).show();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java