简体   繁体   中英

how to fetch response from retrofit JSON without key

In my retrofit JSON response there is a single value without any key and type .In my JSON i have passed three-element as per need and now i get a response as shown below. so how can I fetch that response?

My JSON of Response looks like -

successful

This is my JSON code-

private void ASSIGN_DATA() {

    ApiInterface apiInterface=ApiClient.getClient().create(ApiInterface.class);
    Call<ArrayList<price_get_set>> call=apiInterface.assignItemToJson(select_date.getText().toString(),
                id,item_list);

    call.enqueue(new Callback<ArrayList<price_get_set>>() {

        @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onResponse(Call<ArrayList<price_get_set>> call, Response<ArrayList<price_get_set>> response) {
           progress.dismiss();

            Log.d("URL::",response.toString());

           Log.d("new URL::",response.body().toString());

            try {
                if (response.isSuccessful()) {
                    Toast.makeText(Items_List.this, "Successs", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(Items_List.this, Item_Accept_Reject_List.class);
                    startActivity(intent);
                }
                else
                    Toast.makeText(Items_List.this, "Something went Wrong", Toast.LENGTH_SHORT).show();
                }

            catch (Exception ex){
                Log.e("ERROR::",ex.getMessage());
            }
        }

        @Override
        public void onFailure(Call<ArrayList<price_get_set>> call, Throwable t) {
           progress.dismiss();
           Log.i("FAILURE ERROR::",t.getMessage());
        }
    });
}

You can use response.body().string() . It will convert your response in String.

Example On Your onResponse method of API you have to use this code.

@Override
public void onResponse(Response<ResponseBody> response) {
    try {
        String responseString = response.body().toString();//This a response as string
        Log.d("Response : " + responseString);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM