Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

Open Satyam7779 opened this issue 5 years ago • 3 comments

Main Activity

textViewResult=findViewById(R.id.text_view_result);

    Retrofit retrofit=new Retrofit.Builder()
            .baseUrl("https://feeds.citibikenyc.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    JsonPlaceHolderApi jsonPlaceHolderApi=retrofit.create(JsonPlaceHolderApi.class);

    Call<List<Post>> call=jsonPlaceHolderApi.getPost();

    call.enqueue(new Callback<List<Post>>() {
        @Override
        public void onResponse(Call<List<Post>> call, Response<List<Post>> response) {

            if (!response.isSuccessful()){
                textViewResult.setText("code: " + response.code());
                return;
            }

            List<Post> posts=response.body();
            for (Post post: posts){
                String Content="";
                Content +="ID:"+ post.getId() + "\n";
                Content +="sationName"+ post.getSationName() + "\n";
                Content +="availableDocks" + post.getAvailableDocks() + "\n";
                Content +="totalDocks" + post.getTotalDocks()+ "\n";
                Content +="latitude" + post.getLatitude()+ "\n";
                Content +="longitude" + post.getLongitude()+ "\n";
                Content +="statusValue" + post.getStatusValue()+ "\n";
                Content +="statusKey" + post.getStatusKey()+ "\n";
                Content +="availabeBikes" + post.getAvailabeBikes()+ "\n";
                Content +="stAddress1" + post.getStAddress1()+ "\n";
                Content +="stAddress2" + post.getStAddress2()+ "\n";
                Content +="city" + post.getCity()+ "\n";
                Content +="postalCode" + post.getPostalCode()+ "\n";
                Content +="location" + post.getLocation()+ "\n";
                Content +="altitude" + post.getAltitude()+ "\n";
                Content +="testStation" + post.getTestStation()+ "\n";
                Content +="lastCommunicationTime" + post.getLastCommunicationTime()+ "\n";
                Content +="landmark" + post.getLandmark()+ "\n\n";

                textViewResult.append(Content);

             }
        }

        @Override
        public void onFailure(Call<List<Post>> call, Throwable t) {
        textViewResult.setText(t.getMessage());
        }
    });


}

}

Satyam7779 avatar Jul 26 '19 06:07 Satyam7779

Hello, could you please be more specific about your problem?

zigic88 avatar Jul 27 '19 11:07 zigic88

i have having similar problem. In Registration Response class there is inner class card_data which has some fields.

When i post request for login with required credentails. in response cars_data field is empty.

and i am getting this error message: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 932 path $.data.card_data error detail: parseError

how can this be handled?

RESOLVED:

i was posting card_data as null object. but server was sending empty string in response

so that's why parsing issue occurred.

now server is sending empty array.issue resolved

usmanhashmi2123 avatar Jul 31 '19 07:07 usmanhashmi2123

Hi me too

waihanko avatar Apr 02 '20 16:04 waihanko