Fast-Android-Networking
Fast-Android-Networking copied to clipboard
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
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());
}
});
}
}
Hello, could you please be more specific about your problem?
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
Hi me too